Search Unity

Official Roll-a-ball Tutorial Q&A

Discussion in 'Community Learning & Teaching' started by Adam-Buckner, Apr 17, 2015.

  1. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Evening,

    One thing to look out for are these Braces { } , this denotes code blocks, these are in pairs, for each opening { there is a corresponding closing }.

    if you click your mouse just after one of the braces, it will highlight the corresponding bracket in that pair.
    see the line 24 below to see the bracket that I commented out as it was causing the errors.

    due to the OnTriggerEnter being outwith the main class code blocks, and the final closing bracket didnt have a corresponding opening one. But remove the bracket on line 24 shown below and you should be ok.

    Just takes time and practice to get used to it, keep going :)

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerController : MonoBehaviour {
    5.  
    6.     public float speed;
    7.  
    8.     private Rigidbody rb;
    9.  
    10.     void Start ()
    11.     {
    12.         rb = GetComponent<Rigidbody> ();
    13.     }
    14.  
    15.     void FixedUpdate ()
    16.     {
    17.         float moveHorizontal = Input.GetAxis ("Horizontal");
    18.         float moveVertical = Input.GetAxis ("Vertical");
    19.  
    20.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    21.  
    22.         rb.AddForce (movement * speed);
    23.     }
    24.     //}  extra closing brace, here by accident, if left in this would signify the closing brace of the class
    25.     // which means that all the stuff below would be outwith the class and cause errors like you are getting
    26. void OnTriggerEnter(Collider other)
    27. {
    28.     if (other.gameObject.CompareTag("Pick Up"))
    29.     {
    30.         other.gameObject.SetActive (false);
    31.     }
    32. }
    33. } // so with the } brace commented out above, this is now the proper closing brace for the class code block.
    34. // and therefore your OnTriggerEnter method is correctly encompassed within the class.
     
  2. CCPM

    CCPM

    Joined:
    Aug 22, 2016
    Posts:
    7
    This was very helpful and solved my problem, thank you! [-=
     
  3. CCPM

    CCPM

    Joined:
    Aug 22, 2016
    Posts:
    7
    Got on to the next video in the tutorial, about setting up the text, and right at the part where you drag the words 'count text' into the little text box within the 'playercontroller script' section of the inspector, I noticed that the little text box that needs to be there for me to drag 'count text' into wasn't there, and that's when I checked the console and found more errors; tried to fix them myself, but more often than I got rid of an error, I caused 1 or 2 new ones in the process. If you could tell me how to fix the errors again I'd really appreciate it, and in fact, since I don't know the CSharp language, I may need your help with scripting throughout the rest of the tutorial, and again all of your help will be very much appreciated.
    Here's my playercontroller script as it currently stands:

    using UnityEngine;
    using UnityEngine.UI;
    using System.Collections;

    public class PlayerController : MonoBehaviour {

    public float speed;
    public Text countText;

    private Rigidbody rb;
    private int count;

    void Start ()
    {
    rb = GetComponent<Rigidbody> ();
    count = 0;
    SetCountText ()
    }

    void FixedUpdate ()
    {
    float moveHorizontal = Input.GetAxis ("Horizontal");
    float moveVertical = Input.GetAxis ("Vertical");

    Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);

    rb.AddForce (movement * speed);
    }

    void OnTriggerEnter(Collider other)
    {
    if (other.gameObject.CompareTag("Pick Up"))
    {
    other.gameObject.SetActive (false);
    count = count + 1;
    SetCountText ()
    }
    }

    void SetCountText ()
    {
    countText.text = "Count: " + count.ToString ();
    }
    And here's the first error:

    Assets/Materials/Scripts/PlayerController.cs(18,9): error CS1525: Unexpected symbol '}'
    And it takes me here:





    void Start ()
    {
    rb = GetComponent<Rigidbody> ();
    count = 0;
    SetCountText ()
    } <---that's where it says the problem is

    The second error:

    Assets/Materials/Scripts/PlayerController.cs(37,17): error CS1525: Unexpected symbol '}'
    Takes me here:



    void OnTriggerEnter(Collider other)
    {
    if (other.gameObject.CompareTag("Pick Up"))
    {
    other.gameObject.SetActive (false);
    count = count + 1;
    SetCountText ()
    }<---that's where it says the problem is

    The third error:

    Assets/Materials/Scripts/PlayerController.cs(43,9): error CS1525: Unexpected symbol 'end-of-file'
    Takes me here:


    void SetCountText ()
    {
    countText.text = "Count: " + count.ToString ();
    }<---says it's this line where the problem is

    The fourth and last error:

    Assets/Materials/Scripts/PlayerController.cs(43,9): error CS8025: Parsing error
    Takes me here:

    void SetCountText ()
    {
    countText.text = "Count: " + count.ToString ();
    }<---says this is the line where the problem is

    Thanks a bunch again for all your help! [-=
     
  4. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    ok , when using c# each and every statement must end with a ' ; ' to denote that it is the end

    you are missing this after a couple of lines, so heres the edited sections
    Code (CSharp):
    1.     void Start ()
    2.     {
    3.         rb = GetComponent<Rigidbody> ();
    4.         count = 0;
    5.         SetCountText ();  // you were missing the end of line ;
    6.     }
    here also
    Code (CSharp):
    1.     void OnTriggerEnter(Collider other)
    2.     {
    3.         if (other.gameObject.CompareTag("Pick Up"))
    4.         {
    5.             other.gameObject.SetActive (false);
    6.             count = count + 1;
    7.             SetCountText () ;  // again missing the end of line ;
    8.         }
    9.     }
    and then right at the end, remember what i said about each opening brace { having a corresponding closing } brace.

    right at the very end, you need another
    Code (CSharp):
    1.     void SetCountText ()
    2.     {
    3.         countText.text = "Count: " + count.ToString ();
    4.     }
    5. }  // you are missing the closing } for the class


    also please for future reference, if posting code can you use code tags, it makes it alot easier to follow and has appropriate line numbers where you can direct questions to.

    have a read here.
    http://forum.unity3d.com/threads/using-code-tags-properly.143875/
    (or click in my sig)
     
  5. CCPM

    CCPM

    Joined:
    Aug 22, 2016
    Posts:
    7
    Got it, thanks again for all the help, and I read the link too, I'll remember to do this if I need help again! [-=
     
    OboShape likes this.
  6. MaccRekt

    MaccRekt

    Joined:
    Aug 25, 2016
    Posts:
    1
    Hello
    I just started this "Roll-a-ball tutorial" and I'll just state that I have no education background in programming yet
    so I have this problem upload_2016-8-25_18-7-40.png

    I dont how to fix this so can you help me
     
  7. toki521

    toki521

    Joined:
    Aug 27, 2016
    Posts:
    1
    Error is shown in the code when I follow the code instruction in 14: 19 of the Unity 5 - Roll a Ball game - 2 of 8: Moving the Player - Unity Official Tutorials in



    using UnityEngine;
    using System.Collections;

    public class PlayerController : MonoBehaviour {

    public float speed;

    private Rigidbody rb;

    void Start()
    {
    rb = GetComponent<Rigidbody> ();
    }

    void FixedUpdate()
    {
    float moveHorizontal = Input.GetAxis ("Horizontal");
    float moveVertical = Input.GetAxis ("Vertical");

    Vector3 movement = new Vector3 (moveHorizontal, 0.0f,moveVertical);

    rb.Addforce (movement * speed);

    }
     
  8. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    If you could , can u click on the error in the console, copy and paste the actual error you are receiving please.

    Just out of curiosity and a stab in the dark, do you have a Rigidbody component on the player?
     
    Last edited: Aug 27, 2016
  9. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    doesnt seem to be a script on the Player in your scene looking at the inspector.
    were you getting a missing reference in the inspector previously at all when you were creating the PlayerController script?
     
  10. dtopping

    dtopping

    Joined:
    Aug 28, 2016
    Posts:
    2
    Hi,

    I just downloaded Unity today so am very new to it! I have what is probably a very basic issue with the editor; I can't see the player in the Game view.

    I've attached a screen shot. I'm only on lesson 4 and when I click play the camera does move around as if following the ball but the ball itself is not visible in that window.

    Any idea what I'm missing?

    EDIT - I was missing the -10 setting on the Main Camera's z axis... sorted now.
     

    Attached Files:

    Last edited: Aug 28, 2016
  11. nst101

    nst101

    Joined:
    Aug 28, 2016
    Posts:
    2
    I'm having issues with this tutorial when adding the canvas and text. I add a canvas through the project create>UI>Text menu, but the canvas and text is huge! I cannot get the canvas and text to size down to my game board. I have attached some screenshots to show the size. Any help would be much appreciated (new to Unity here)!
    Capture.PNG Capture2.PNG
     
  12. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Looking at the canvas in the scene window, it seems large, however this is normal, the size is driven by the rect transform, as opposed to the normal transform you see on game objects.

    In screen space overlay mode (like we have it here) its designed to fit in the game window (ie what the camera sees), its just that its a higher resolution, its something like a world space unit per pixel or something like that, not sure.
    best to work with the UI in 2d mode by toggling the 2D button above the scene window when moving stuff around the UI canvas.

    for more info on the UI you can view the modules here
    https://unity3d.com/learn/tutorials/topics/user-interface-ui
     
  13. nst101

    nst101

    Joined:
    Aug 28, 2016
    Posts:
    2
    Thanks! I'll give the 2D a try. Another question: should I switch the canvas to world mode? I was researching and found that would allow me to resize the canvas. The problem I was finding with that, though, was the text was still huge.
     
  14. p4ndepravity

    p4ndepravity

    Joined:
    Aug 31, 2016
    Posts:
    2
    I am really enjoying getting into unity. I'm a developer who began pursuing development with game dev in mind. Now, with platforms like unity, personal development in my spare time is simple. This tutorial is well-made and highly educational. The only feedback I have is, by following this tutorial with zero experience using unity, the roll-a-ball game will look completely different than the example in the video. I had to do pretty extensive research on how to make my surfaces and objects look the same as the sample in the video. Specifically regarding the lighting, I think it would be more meaningful to viewers if you spent some time (if not, then a couple quick instructions) on how to setup the lighting, especially the ambient lighting. It could be that my version of unity comes with different defaults for new projects, but now that my lighting is setup correctly, my roll-a-ball game looks exactly like the sample in the video, and it feels more polished/professional. You would be surprised by the difference it makes for a beginner's enthusiasm when they feel like they are making top-tier product, even if its just a sample game for a tutorial.

    Thanks a ton for creating this video series and I cannot wait to follow along with the more advanced tutorials!

    Trent
     
  15. LucidFlare

    LucidFlare

    Joined:
    Nov 28, 2015
    Posts:
    1
    Hi everyone. I've been having a blast doing this tutorial so far but I've run into and issue that I simply can't find the answer to. For some reason I've getting this error.

    NullReferenceException: Object reference not set to an instance of an object
    PlayerController.FixedUpdate () (at Assets/Scripts/PlayerController.cs:28)

    Here's the script

    using UnityEngine;
    using UnityEngine.UI;
    using System.Collections;

    public class PlayerController : MonoBehaviour {

    public float speed;
    public Text countText;

    private Rigidbody rb;
    private int count;

    // Update: Called before rendering a frame
    void start ()
    {
    rb = GetComponent<Rigidbody>();
    count = 0;
    SetCountText ();
    }
    // FixedUpdate: Is called just before performing any physics calculations
    void FixedUpdate ()
    {
    float moveHorizontal = Input.GetAxis ("Horizontal");
    float moveVertical = Input.GetAxis ("Vertical");

    Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);

    rb.AddForce (movement * speed);
    }

    void OnTriggerEnter(Collider other)
    {
    if (other.gameObject.CompareTag ( "Pick Up"))
    {
    other.gameObject.SetActive (false);
    count = count + 1;
    SetCountText ();
    }
    }

    void SetCountText ()
    {
    countText.text = "Count: " + count.ToString ();
    }
    }


    I can't get it to count when I pick up one of the pickups either. I know i'm probably missing something very simple but I've compared to with the script that is below the video I'm on. It seems to be the exact same thing and that works...mine won't though.
     
  16. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Its not assigning anything to the rb reference and so will be null.
    this is down to your Start method.
    Code (CSharp):
    1. void start ()
    this should be
    Code (CSharp):
    1. void Start ()
    C# is case sensitive, a lower case S in this wont call the method, it wont throw an error either, it just wont be called.
    try that and see.
     
  17. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    there is a large compilation of tutorial modules available.
    If you have a look theres a few on lighting that may help
    https://unity3d.com/learn/tutorials/topics/graphics
     
  18. Deleted User

    Deleted User

    Guest

    Hey, I have a problem. The whole script of my code is exactly how the man explained it and created it. But every time I click 'Play', the ball will pop up to a full 1 unit on the Y axis above the plane. No matter what I do, it always does the same. What's going on? Is it something to do with my actual system?
     
  19. PSRich

    PSRich

    Joined:
    Sep 3, 2016
    Posts:
    2
    Hi and thanks for having this area for questions from newcomers. So, here's mine:

    I suspect (ok, actually I'm positive) it's something I'm doing wrong however the very first tutorial (roller ball game) shows a completely different screen set up than the roller ball tutorial. I only see assets in the bottom not the game view. I can click camera and the game view will pop up in the 'grid' screen. I'd like it to look exactly like the tutorial so I can follow along. What am I missing? It's this way from the absolute start. Please let me know. I've watch the video repeatedly and still don't see my error.

    Thanks, Rich.
     
  20. PSRich

    PSRich

    Joined:
    Sep 3, 2016
    Posts:
    2
    I'm answering my own question just in case anyone else runs into this issue. Turns out there are 'get acquainted with interface' tutorials too. Unity certainly did send this info to me, it just all went to JUNK folder unlike the other stuff which went to 'normal' email. Who knows why...but there it was. I'll watch now and hopefully that will answer my questions....

    Cheers and good luck all!
     
    OboShape likes this.
  21. burakokumus

    burakokumus

    Joined:
    Aug 25, 2016
    Posts:
    8
    Right now i'm on the 5th step of the tutorial, i'm sure i did everything as shown, but when i try to change color of pick ups, i have to do it 1 by 1. In video he says there are 2 ways. I tried both, in the first way there is no apply button nor anything about prefabs. In the second way nothing happens when i put the material into the prefab. How can i solve this problem?
     
    irishdjali likes this.
  22. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    any chance you could post your playercontroller script please for a look, sounds like you may be setting the Y on the player ball, a screenshot of the inspector with the ball highlighted would be useful too.
    ( if you could use code tags when posting scripts as well please, see the sig for into, makes it easier to read cheers)
     
  23. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    there are layout presets that you can select in the upper right. Default, or 2x3 would give similar.

    as each window is movable, you can also click and drag the title tab and it will either dock or float depending where you would like it to appear. adjust to taste.

    for info its in the manual page here under customizing workspace.
    https://docs.unity3d.com/Manual/CustomizingYourWorkspace.html
     
  24. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Just wondering, did you create one pickup, make the prefab, and then drag the prefab into the scene to create the other pickups?

    that way, i think the prefab changes would reflect in the others too. Ill have to test to double check tomorrow.
     
  25. ppix

    ppix

    Joined:
    Sep 6, 2016
    Posts:
    5
    I completed and enjoyed the tutorial, but ran into a problem at the very end:
    The game works just as in the tutorial when I play it inside the Unity Editor.
    But after building it as an OSX 64bit app the player ball does not trigger the pick ups in the resulting app. That is, the ball rolls through the yellow cubes without them disappearing or the displayed count being incremented.
    I am using Unity version 5.4.0.f3 (Personal) on Mac OSX 10.11.6.
     
    irishdjali likes this.
  26. ALopez2

    ALopez2

    Joined:
    Sep 7, 2016
    Posts:
    5
    what keys am i supposed to move it with? the tutorial doesn't say. and it's not showing any errors.i cant get the ball to move. Screen Shot 2016-09-07 at 6.14.02 AM.png what else is wrong????

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerControler : MonoBehaviour {
    5.  
    6.     private Rigidbody rb;
    7.  
    8.     void Start ()
    9.     {
    10.         rb = GetComponent<Rigidbody>();
    11.     }
    12.  
    13.     void FixedUpdate ()
    14.     {
    15.         float moveHorizotal = Input.GetAxis ("Horizantal");
    16.         float moveVertical = Input.GetAxis ("Vertical");
    17.  
    18.         Vector3 movement = new Vector3 (moveHorizotal, 0.0f, moveVertical);
    19.  
    20.         rb.AddForce (movement);
    21.     }
    22. }
     
  27. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836

    Should just be the arrow keys or WASD as defaults.

    Have a look, im assuming that the playercontroller script is attached to the player?
    in the rigidbody component, have a quick look to see if 'is kinematic' is checked, if it is, uncheck and test.

    if not, can you post a screenshot showing your inspector with the player selected please.
     
  28. MatthewDoucette

    MatthewDoucette

    Joined:
    Sep 9, 2016
    Posts:
    1
    I could not find where this code was. Do you have the final project and code available for your tutorials?
     
  29. irishdjali

    irishdjali

    Joined:
    Sep 11, 2016
    Posts:
    5
    I completed the tutorial and it works beautifully within the Unity Engine program, No errors in the console, the ball collects the cubes and eventually you win.

    I followed the steps to create the build, and I did it successfully. It comes up and I can move the ball. However, the cubes don't collect.

    Any idea why that's happening?
     
  30. irishdjali

    irishdjali

    Joined:
    Sep 11, 2016
    Posts:
    5
    @OboShape , any thoughts?
     
  31. Toe-Bar

    Toe-Bar

    Joined:
    Sep 13, 2016
    Posts:
    1
    Hi absolute newbie to Unity and game design.

    Downloaded Unity Yesterday and started on the Roll-a-ball game as a first.
    My work space doesn't show like in the tutorial, I am not seeing shading or sky and the game panel is showing Display 1 no cameras rendering.
    What has gone wrong please?
    upload_2016-9-13_14-57-29.png
     
  32. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    The code posted underneath the relevant video in the tutorials on the following page, looks like they have been updated with Unity 5 in mind.
    https://unity3d.com/learn/tutorials/projects/roll-ball-tutorial
     
  33. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    one thing to try, with your scene that is working correctly open.
    if you go to build settings. in the top part of that page it shows the scenes that will be used in your exported game. highlight each one and remove, then press 'add open scenes' and try and build from there, see if that helps.

    this will just set the build settings to just include your one open scene that you have, just something to test.
    is it PC / standalone you are building to as the platform? (in the build settings , the current platform is indicated by the unity logo along side it, or on the top bar of your editor window)
     
  34. irishdjali

    irishdjali

    Joined:
    Sep 11, 2016
    Posts:
    5
    @OboShape

    I figured it out. For some reason, even though it worked in the editor, the tag wasn't sticking when I made the build. Oddly, it showed as undefined, so I selected Pick Up again.

    Build didn't work. Went back, and the Pick Up tag disappeared completely as an option. Recreated, build and run, and voila, it worked this time.

    No idea what was going on, but thanks!
     

    Attached Files:

  35. WerdnaK

    WerdnaK

    Joined:
    Sep 15, 2016
    Posts:
    1
    Sorry if this was covered already. On the Creating Collectables portion of the lesson, when instructed to move the cube in the top down view while global is selected, the cube moves only on x and y but not z. I have 0 experience in unity aside from the last hour it took to get this far. Thank you for your time.
     
  36. killingmad

    killingmad

    Joined:
    Sep 16, 2016
    Posts:
    2
    Okay so I dont mean to be rash but i am getting non stop errors when trying to execute simple scripts. Not just from this tutorial but several others now. I have paused the screen on the video lessons and made sure my scripts are copied down the the last space and everything. I am getting very irritable with this as im a new user but dont understand what im doing wrong - please help! Screenshots to follow

    <<Error Message

    << My code

    <<< Tutorial code
     
  37. killingmad

    killingmad

    Joined:
    Sep 16, 2016
    Posts:
    2
    Screenshots
     

    Attached Files:

  38. burakokumus

    burakokumus

    Joined:
    Aug 25, 2016
    Posts:
    8
    I completed and enjoyed the tutorial. @OboShape i didn't understeand what you meant but it doesn't matter, solved it myself. Now what should i do? How should i continue?
     
  39. hamsel

    hamsel

    Joined:
    Sep 17, 2016
    Posts:
    1
    I've had this problem while doing the tutorial and saw plenty of others here and on youtube with no solutions about what's wrong or how to fix it.

    The problem:
    I'm very new to Unity so I don't totally understand it, but I found the problem was I was still in "play mode". It seems like you can still use the editor to do many things, but it doesn't do it properly. At some stage I've hit "play mode" and when you do that it causes the above problems.

    The solution:
    Just exit "play mode". You might lose progress on what you've done, like creating the extra pickups, but now everything will work as intended.

    I think this is probably just something new users run into, when you are new to the interface you don't really notice the shading over the UI and don't realise being in play mode has these effects.
     
  40. RobertTheG

    RobertTheG

    Joined:
    Sep 19, 2016
    Posts:
    1
    for some reason i cant drag the count text game object into the player component for the script. in fact when i click the little browse button to see all the text files there is nothing.
    this is my player controller script:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;
    4.  
    5. public class PlayerController : MonoBehaviour
    6. {
    7.  
    8.     public float speed;
    9.     public Text countText;
    10.  
    11.     private Rigidbody rb;
    12.     private int count;
    13.  
    14.     void Start()
    15.     {
    16.         rb = GetComponent<Rigidbody>();
    17.         count = 0;
    18.         SetCountText ();
    19.     }
    20.  
    21.     void FixedUpdate()
    22.     {
    23.         float moveHorizontal = Input.GetAxis("Horizontal");
    24.         float moveVertical = Input.GetAxis("Vertical");
    25.  
    26.         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    27.  
    28.         rb.AddForce(movement * speed);
    29.     }
    30.  
    31.     void OnTriggerEnter(Collider other)
    32.     {
    33.         if (other.gameObject.CompareTag("Pick Up"))
    34.         {
    35.             other.gameObject.SetActive(false);
    36.             count = count + 1;
    37.             SetCountText ();
    38.         }
    39.     }
    40.    
    41.     void SetCountText ()
    42.     {
    43.         countText.text = "Count: " + count.ToString ();
    44.     }
    45. }
    pls help me this is very frustrating
     
  41. Pocketknife316

    Pocketknife316

    Joined:
    Sep 21, 2016
    Posts:
    6
    I am on 'moving the player' and when I hit play and push the keys, the ball won't move. Also when I hit play, a message appears at the bottom of the screen saying:

    NullReferenceException: Object reference not set to an instance of an object
    PlayerController.FixedUpdate () (at Assets/Scripts/PlayerController.cs:24)
     
  42. AndreaH

    AndreaH

    Joined:
    Sep 22, 2016
    Posts:
    1
    Hey, I'm about to begin the tutorial. Could you tell me where I can play the finished game first?
    Thank you!
     
  43. KAYUMIY

    KAYUMIY

    Joined:
    Nov 12, 2015
    Posts:
    115
    Code (CSharp):
    1. void OnTriggerEnter(Collider other)
    2.     {
    3.         if (other.gameObject.CompareTag ("Pick Up"))
    4.         {
    5.             other.gameObject.SetActive (false);
    6.         }
    7.     }
    Why did we diactivate the objects rather than destroy?
    When Do I need to destroy the objects?
    When Do I need to diactivate the objects?
    How do I know for sure that which one is better?
     
  44. AshwinTheGammer

    AshwinTheGammer

    Joined:
    Sep 23, 2016
    Posts:
    69
    When I was pressing arrow keys camera is moving left, right, up and down ball is not moving
    Why?
    I am using the Unity 5.4.1
    HELP ME !!!!!! tHANKS
     
  45. Ashton_Audio

    Ashton_Audio

    Joined:
    Sep 27, 2016
    Posts:
    11
    Hi Adam

    Thanks for the help so far I completed the project and now trying to elaborate on this, I've only been using Unity for a couple of days.

    I wanted to find out how to use a variable from script in another one.

    As an experiment now I want to take the 'count' variable and use it to turn the camera off when I've collected all the pickups.

    So I think what I need to do is create a script on the camera object like

    Code (CSharp):
    1. void Update()
    2.     {
    3.      if (count > 9)
    4.         {
    5.           gameObject.SetActive(false);
    6.         }
    7.     }
    8. }
    But how do I get the count variable into this script?
    I already made sure that it is a public int

    Thanks
     
  46. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    the Transform gizmo in the scene that shows when you highlight the object, the thing that shows the Red (x axis), Green (y axis) and Blue (Z axis) arrows. you can click and drag the arrow head and the highlighted object will move along that axis if dragging isnt working as you would expect.
     
  47. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Evening,

    Looking at the screenshot that is labelled "myScript", on line 9 you have the following;
    Code (CSharp):
    1. rb = GetComponent<RigidBody>();
    this should be
    Code (CSharp):
    1. rb = GetComponent<Rigidbody>();
    with that case sensitivity ie the lower case b in Rigidbody, have a try of that see how you get on.
     
  48. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    have a try of the other tutorial series on the learn site, like the UFO game or the SpaceShooter
    https://unity3d.com/learn/tutorials
     
  49. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    strange, have you got a screenshot, showing the Text object highlighted, and one with the playercontroller script highlighed. just to see both things in the inspector to get a better idea of whats happening.
     
  50. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Would be of help if you could include your PlayerController script.
    But at a guess, I would ask you to have a look at your Start() method and comparing to the below, ensuring it is exact in case and spelling to that of the tutorial script. sounds like the rigidbody reference is not being set.

    Code (CSharp):
    1.  void Start ()
    2.     {
    3.         rb = GetComponent<Rigidbody>();
    4.     }