Intermediate Unity 3D for iOS: Part 3/3

Discussion of the official tutorials published on raywenderlich.com. Please only discuss the official tutorials here - for general questions, use the General Discussion forum instead.

Intermediate Unity 3D for iOS: Part 3/3

Postby rwenderlich » Thu Jan 17, 2013 11:00 am

This is the official thread to discuss the following blog post: Intermediate Unity 3D for iOS: Part 3/3
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
User avatar
rwenderlich
Team Member
Site Admin
 
Posts: 2155
Joined: Thu Dec 23, 2010 4:14 pm
Has thanked: 28 times
Been thanked: 343 times

Re: Intermediate Unity 3D for iOS: Part 3/3

Postby avispafuu » Sat Jan 19, 2013 2:42 pm

Hi:

I want to thank you for the great tutorial you made. It's incredible that you offered this work for free for hobbysts like me.

The question is that I've been importing the final project into Unity 4 and, unfortunately, the syntax included in the scripts is not compatible. The compiler shows many errors/warnings that I can't solve by myself.

Would it be possible to post an already Unity 4 converted version?

Thank you so much again for your big effort.

Keep up the good work guys.
avispafuu
n00b
 
Posts: 2
Joined: Tue Aug 28, 2012 10:11 am
Has thanked: 0 time
Been thanked: 0 time

Re: Intermediate Unity 3D for iOS: Part 3/3

Postby josh_newnham » Sun Jan 20, 2013 8:06 pm

Hi,

Glad you liked the tutorial.

Any chance you can elaborate on exactly what the error is you're getting (copy & paste the error/log) - and we'll try to figure out what may be the issue.

Cheers,
Josh
josh_newnham
Baby Hacker
 
Posts: 6
Joined: Sun Jan 20, 2013 8:04 pm
Has thanked: 0 time
Been thanked: 1 time

Re: Intermediate Unity 3D for iOS: Part 3/3

Postby poolenc » Tue Jan 22, 2013 5:06 am

The error I get is on line 69 of GameMenuController.cs it's a 'parser error' unexpected symbol ' } '. The last } in the script.
poolenc
n00b
 
Posts: 1
Joined: Thu Sep 20, 2012 3:22 am
Has thanked: 0 time
Been thanked: 0 time

Re: Intermediate Unity 3D for iOS: Part 3/3

Postby josh_newnham » Tue Jan 22, 2013 3:49 pm

Hi - thanks for getting back.

I suspect that's the issue then.

In the code snippets for the GameMenuController's OnGUI method; the final line has a '}' which is associated with the '{' of the OnGUI method. Can you look over your code and ensure that the OnGUI method has the correct opening and closing blocks.

If you're still running into issues - upload the file here and I'll have a look at it.

Josh
josh_newnham
Baby Hacker
 
Posts: 6
Joined: Sun Jan 20, 2013 8:04 pm
Has thanked: 0 time
Been thanked: 1 time

Re: Intermediate Unity 3D for iOS: Part 3/3

Postby avispafuu » Wed Jan 23, 2013 8:29 pm

Hello again and thanks for your reply.

Once this syntax error is removed, other warnings and errors appear in other clases. I've attached a picture of the log window showing the list of problems found after the correction of the extra '}'. I'm not sure if errors could keep on coming up as the manual conversion process takes place, due to the changes made in the Unity 4 architecture. Anyway, thanks again for your help and support.

Greetings.
Attachments
unity4_other_errors.png
Other errors that appear during the Unity 3 to Unity 4 conversion
unity4_other_errors.png (79.03 KiB) Viewed 3561 times
avispafuu
n00b
 
Posts: 2
Joined: Tue Aug 28, 2012 10:11 am
Has thanked: 0 time
Been thanked: 0 time

Re: Intermediate Unity 3D for iOS: Part 3/3

Postby josh_newnham » Fri Jan 25, 2013 9:10 am

Hi,

There is nothing fancy going on so I would be surprised if using Unity 4 (in this instance) would be causing any issue. At a guess I'm thinking it has something to do with the encoding i.e. how are you copying the code out?

Just to be sure; can you confirm you have the methods it's complaining about in your GameMenuController.cs file;

Code: Select all
public void Show(){
      // ignore if you are already enabled
      if( this.enabled ){
         return;    
      }
      _globalTintAlpha = 0.0f;
      _leaderboardController.FetchScores();
      this.enabled = true;
   }
 
   public void Hide(){
      this.enabled = false;
   }


The methods are described in the 'Showing and hiding' section of the tutorial.

... we're slowly getting there ;)
josh_newnham
Baby Hacker
 
Posts: 6
Joined: Sun Jan 20, 2013 8:04 pm
Has thanked: 0 time
Been thanked: 1 time

Re: Intermediate Unity 3D for iOS: Part 3/3

Postby Saliom » Fri Jan 25, 2013 10:03 am

Hi,

First, thank you so much for this tutorial :) you did a really great job :).

Now, i have encountered a little error while copying your code from the Main menu section, it did tell me that it didn't know any List object, i found the using line i needed to add for it to compile (thx google :D) : using System.Collections.Generic;



Now, i have a question, i'm trying to change the throwball vector using the point where the user clicked so i can make an elipse with the ball if i want, or a straight shoot, or...
But i encoutered a calculation problem, when i take the touch/click position, it's expressed in screen coordinate (iphone 480x320) and not in the scene space coordinate which i guess would me something like (4x2).

To be a bit more clear, i'll use the ball position, let's say the ball is exactly at the center of the screen from the Main camera pov, and at the center of the scene too.
the scene position of the ball is : (1;1;0) Vector3
but the screen position of the ball is : (240;160) Vector2

so how can i perform the calculation of a vector that uses the scene positions so that the ball doesn't run way too far away?? :)

(i could give you the code i added if you'd like :) )


Again, thx a lot for that tutorial, i've been wanting to do some stuff with unity3D for a long time now :)
Saliom
Baby Hacker
 
Posts: 7
Joined: Thu Jan 10, 2013 11:43 am
Has thanked: 1 time
Been thanked: 0 time

Re: Intermediate Unity 3D for iOS: Part 3/3

Postby josh_newnham » Sat Jan 26, 2013 2:18 pm

Hi,

Not exactly 100% sure what you're trying to do but think I understand your question.

In 3D you have 3 spaces, Screen, viewport, and World - what you're trying to do is translate the screen space (points) into 3D. Luckily Unity provides helper methods to make this easier for you; have a read of the following link which explains the Camera.ScreenToWorldSpace method.

http://docs.unity3d.com/Documentation/S ... Point.html

An alternative is to cast a ray out onto a collider and use the hit point. Once again; Unity provides you with the necessary method to convert screen points to a world ray cast;
http://docs.unity3d.com/Documentation/S ... ToRay.html

Josh
josh_newnham
Baby Hacker
 
Posts: 6
Joined: Sun Jan 20, 2013 8:04 pm
Has thanked: 0 time
Been thanked: 1 time

Re: Intermediate Unity 3D for iOS: Part 3/3

Postby Saliom » Mon Jan 28, 2013 11:30 am

it should be working with the ScreenToWorldPoint i think :)

So i'll try to explain a bit better what i'm trying to do.
I'd like that when the user touch the screend, the ball goes in the direction of that touch.

so in the attachment the touch is the red dot, and the green line is what the ball would do, but if i did push a bit upper of the red dot, the ball would have gone a bit higher, if i pushed lower of the red dot, the ball would have gone lower, ...
is it more clear? :)

Capture d’écran 2013-01-28 à 12.20.40.png
example of what i'm trying to do
Capture d’écran 2013-01-28 à 12.20.40.png (170.67 KiB) Viewed 3445 times



here is what i have :
in the Player script
Code: Select all
   if( _state == PlayerStateEnum.BouncingBall ){   
          if( _holdingBall ){
              if( GameController.SharedInstance.State == GameController.GameStateEnum.Play && GameController.SharedInstance.TouchDownCount >= 1 ){
               
               Vector2 touchPosition = GameController.SharedInstance.FirstTouchVector;
               
               Camera camera = Camera.mainCamera;
                  
                throwDirection = camera.ScreenToWorldPoint(new Vector3(touchPosition.x,touchPosition.y,0.0f));
               
               Debug.Log(throwDirection);
               
                  State = PlayerStateEnum.PreparingToThrow;
                  return;
              }
          }


in the GameController for the FirstTouchVector function :

Code: Select all
public Vector2 FirstTouchVector
   {
      get{
         if( IsMobile ){
            Debug.Log("position : "+Input.touches[0].position);
            return Input.touches[0].position;
         } else{
               Debug.Log("position : "+Input.mousePosition);
               Vector3 mouseVector = Input.mousePosition;
               
               return new Vector2(mouseVector.x,mouseVector.y);
         }
      }   
   }


i'm currently only trying it on the computer, and not on an ios device.

It's almost right, but i have to calculate throwDirection from the ball, which isn't done yet, and i don't really see how i could do it...
Saliom
Baby Hacker
 
Posts: 7
Joined: Thu Jan 10, 2013 11:43 am
Has thanked: 1 time
Been thanked: 0 time

Next

Return to Official Tutorials

Who is online

Users browsing this forum: No registered users and 10 guests