Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Official Roll-a-ball Tutorial Q&A

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

  1. awiz911

    awiz911

    Joined:
    Jul 28, 2018
    Posts:
    2
    On Youtube found the official video and it plays just fine.
     
  2. Fardyman

    Fardyman

    Joined:
    Aug 17, 2018
    Posts:
    2
    Hi. In the "Moving the player" part of the Roll a ball tutorial opening a script takes you to a certain editor where you can type words and then press (Ctrl + ') to find info about it in the Unity documentation. When I open scripts it takes me to visual studio from which I can not access documentation in the same way. I was wondering if there is a similar shortcut to unity documentation that I can use in the Visual Studio IDE, or perhaps you can tell me how to open the script without visual studio and with the editor used in the tutorial instead.
     
  3. isotian

    isotian

    Joined:
    Mar 8, 2015
    Posts:
    6
    Hello dear gamedevelopers and Unity-Team,

    I started a project with the goal of making a collaboration of levels made with this tutorial. You can find it here: https://itch.io/jam/playingwithexpectations
    I think it's a good next step after finishing this tutorial to work together with other developers who have done the same. It also gives you a first experience working on a remote project with tools like git. Hope some of you like the idea and want to participate.

    Greeting,
     
  4. jakobia

    jakobia

    Joined:
    Aug 7, 2018
    Posts:
    1
    I have a problem in this code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerController : MonoBehaviour {
    6.  
    7.     public float speed;
    8.  
    9.     private Rigidbody rb;
    10.  
    11.     void Start()
    12.     {
    13.         rb.GetComponent<Rigidbody>();
    14.     }
    15.  
    16.     void FixedUpdate()
    17.     {
    18.         float moveHorizontal = Input.GetAxis("Horizontal");
    19.         float moveVertical = Input.GetAxis("Vertical");
    20.  
    21.         Vector3 movement = new Vector3(moveHorizontal,0.0f,moveVertical);
    22.  
    23.         rb.AddForce(movement*speed);
    24.     }
    25. }
    in unity:

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

    GoSlowGames

    Joined:
    Feb 8, 2018
    Posts:
    3
    hi I was wondering if there was a place where I can learn how to make enemy ai and code in c# cos I want to make an enemy in the roll a ball game that is like the Mario enemy if you hit it on the side you die but I want it to follow a set path aswell if anyone knows where I can find some where to learn this that would be grate
     
  6. jackvob1

    jackvob1

    Joined:
    Mar 2, 2018
    Posts:
    38
    Hi, I want to ask about the rigidbody in the pick up object, I try to change the settings but I always fail to add gravity to the object, when I can add the gravity the pick up object passed through the ground. any advice ?

    P.S.
    I'm new to Unity
     
  7. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144

    You haven't assigned anything to rb
    You declared it at line 9 (at which point it is null)
    You made a reference to it at line 13 (which would be null since rb is null)
    And you tried to use it at line 23.

    Change line 13 to:
    rb = GetComponent<Rigidbody>();
     
    NPWGames likes this.
  8. Mine4ever

    Mine4ever

    Joined:
    Sep 22, 2018
    Posts:
    1
    I created the roll ball game successfully and it worked well, but there always was an error in the console: "NullReferenceException: Object reference not set to an instance of an object".
    The reason of this error is the code "countText.text = "Count: " + count.ToString();".
    This bug seems to have no effect on the program,but I still want to know why.
    I'd appreciate it if someone could help me.
     
  9. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,318
    You've skipped the part of the tutorial instructing you how to place the camera so that the game looks like in the tutorial when you play it.
     
  10. dzikaszyszka

    dzikaszyszka

    Joined:
    Sep 22, 2018
    Posts:
    1
    Ah, I deleted the post because I went over the tutorial again and fixed it already. Thanks for the fast answer! Must have not save the values during the step.
     
  11. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,318
    Hi,
    In case people would wonder if this tutorial is reliable or not, I can tell you that I remade it with Unity 2018.2xf1 and that everything went perfectly well.
    This tutorial is perfect for people who never used Unity nor wrote any code before.
     
  12. Naiskick

    Naiskick

    Joined:
    Oct 14, 2018
    Posts:
    12
    Hi,
    I have done what the video told me to do but in my project the cubes don't disappear when the ball hit them.
    I thought there is something I missed,but I can't find out what is it.
    Is it a problem about tag?But the video didn't tell me to do something about adding tag,or I just missed it?
    Would you help me figure out why the cubes don't disappear?

    the name of the cube(Prefab) is "PickUp" too,I'm not sure which is the correct "Tag" I should name right,
    even I don't understand what the "tag" is.Is the name of object or name of Prefab or I should add a new tag for the Prefabs call "PickUp" in the inspector panel ?

    Hope you reply.Thanks a lot:)

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class Playercontroller : MonoBehaviour
    7. {
    8.  
    9.     public float speed;
    10.     public Text countText;
    11.  
    12.     private Rigidbody rb;
    13.     private int count;
    14.  
    15.     void Start()
    16.     {
    17.         rb = GetComponent<Rigidbody>();
    18.         count = 0;
    19.         SetCountText();
    20.     }
    21.  
    22.     void FixedUpdate()
    23.     {
    24.         float moveHorizontal = Input.GetAxis("Horizontal");
    25.         float moveVertical = Input.GetAxis("Vertical");
    26.  
    27.         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    28.  
    29.         rb.AddForce(movement * speed);
    30.  
    31.     }
    32.  
    33.     void OnTriggerEnter(Collider other)
    34.     {
    35.         if (other.gameObject.CompareTag("PickUp"))
    36.         {
    37.             other.gameObject.SetActive(false);
    38.             count = count + 1;
    39.             SetCountText();
    40.         }
    41.     }
    42.  
    43.  
    44.     void SetCountText()
    45.     {
    46.         countText.text = "Count:" + count.ToString();
    47.     }
    48. }
    49.  
     
  13. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,318
    Nine times in ten, when this kind of things happens, it's just because you overlooked something. Go back to the video and verify everything step by step. Developing is a trial by patience. ;)
     
  14. Naiskick

    Naiskick

    Joined:
    Oct 14, 2018
    Posts:
    12
    Well,I will take your suggestion:DLet me go back to the video.
    Wait for my update!
     
  15. Naiskick

    Naiskick

    Joined:
    Oct 14, 2018
    Posts:
    12
    As you said, I missed one entire video which show me how to deal with tag..Oh my..
    So embarrassing!
    Thank you for your kindly remind ,you sovled the problem for me.:)
     
    APSchmidt likes this.
  16. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,318
    Glad you sorted out! There's nothing embarrassing here; we all had our "moments". ;)
     
  17. Naiskick

    Naiskick

    Joined:
    Oct 14, 2018
    Posts:
    12
    Emmm..Sorry to bother you again.But another "moment" has come to me.:oops:
    I built the game as the video said.When I run the program ,it shows nothing but a grey and blue background just like a skybox. I can't play anything. But in the Unity the game run perfectly!
    Is it because I am using personal edition of Unity.. ?
    Or I chose the wrong platform when I built the game? I run Unity on the PC with Win10. Which platform should I choose? PC or Universal Windows Platform?
     
  18. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,318
    I should tell you to rerun the last video of the tutorial where the how to build the game is expalained but my best bet is that you didn't add the scene to the build settings.
     
  19. Naiskick

    Naiskick

    Joined:
    Oct 14, 2018
    Posts:
    12
    I had added the only one scene called "Minigame",I think this is the right target..I dragged it from project view to the build settings,click the "Build" button,and create a new folder placed on the root of the project alongside the assets and library folders,then save the build in this new folder.
    And "Build completed with a result of succeeded" has bees shown at the bottom of the screen.
    Am I doing right? I don't know why the build can't run properly..
     
  20. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,318
    Why did you drag the scene instead of using the "Add To Scene" button? Did you make sure the scene was selected?

    Capture.JPG
     
  21. Naiskick

    Naiskick

    Joined:
    Oct 14, 2018
    Posts:
    12
    Yes ,I'm sure the scene was selected.
    The last video said there are two ways to select the scenes: drag it to Build setting or click the "Add open scenes" button.then I dragged it.
    In the "Scenes In Build" window there are two scenes.The SampleScene is already there when I opened Build setting at the first time.
    I rebuilt several times but the problem still there.
    Looking forward to your kindly suggestion.


    Scenes in the projects view


    Scene was selected




    Folders arrangement





    Nothing shows in the program
     
  22. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,318
    There is your problem, you must remove the sample scene. After being built, the game starts on the first scene on the list. ;)
     
  23. Naiskick

    Naiskick

    Joined:
    Oct 14, 2018
    Posts:
    12
    I deleted the SampleScene and then ...
    Yeah! I did it!
    The evil SampleScene...Next time I will do exactly what the video said..
    Thanks god I met a experienced developer likes you !! You help me so much:D
    ;)
     
  24. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,318
    I'm not that experienced... :)

    Thank you for the nice image! :D
     
  25. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,318
    Maybe you shouldn't have copied and pasted the code but write it yourself. What script did you copy and paste exactly? Post a link to the project video page and give me the name of the script.
     
  26. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,318
    You overlooked something then. :)

    Sorry for assuming; I'm not much awake yet.
     
  27. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,318
    The only thing I can think of if that, for some reason, the default input settings have been modified. You can find them in Edit/Project Settings/Input. More about the input manager here: https://docs.unity3d.com/Manual/class-InputManager.html
     
  28. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,318
    Yes, it should.

    Tick it and see what happens; if it does restore the correct movement, your problem comes from elsewhere.
     
  29. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,318
    Yes, that's the biggest task for you right now; I doubt that this behaviour is Unity related.

    Are the arrows working the right way in other software or games where you have to use them?
     
  30. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,318
    Also, is your computer set to write languages that read from the right to the left?
     
  31. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,318
    Does this happen in other Unity projects or in a completely new and empty one?
     
  32. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,318
    If you did get the same results in an entirely new project then you should create a thread describing your problem here: https://forum.unity.com/forums/editor-general-support.10/

    If nobody can find a solution, you'll have to file a bug report, knowing that, if the support team cannot reproduce the problem, they won't be able to fix it...
     
  33. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    8,752
    You're looking at the object from the other side. You need to rotate your camera around the object 180 degrees and your directions will be fixed.
     
    APSchmidt likes this.
  34. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,318
    Ha! I hadn't thought about that... :D I hope this is the fix.
     
  35. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    8,752
    It is, AddForce is applying force in world space which means you can even rotate your object around and have it move in the "wrong" direction. :D
    But since world space is also relative to the camera position, you can have a (seemingly) "wrong" direction.
     
  36. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,318
    I understand but I'm not sure you can watch the ball from "the other side" in the Roll a Ball project since the camera is supposed to follow the ball around. :)
     
  37. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    8,752
    There is always an other side and the grass is always greener there! ;)

    I guess he didn't implemented the following part yet.
     
  38. fmorrison

    fmorrison

    Joined:
    Nov 24, 2018
    Posts:
    2
    Where is the best place to figure out why, when starting Roll-a-Ball from inside Unity 2018.2.17f1 via download and start and then trying to exit and save, I get the following error that I cannot get around?:

    moving C:/users/fpmor/AppData/Local/Temp/75c...b45 to c:/projects/unity/Roll-A-Ball the process cannot access the file because it is being used by another process (try again, force quit, cancel).

    All I did was wait for the project to open, then tried to exit Unity 2018.2.17f1 and save the project on the way out.
     
  39. andreasele22

    andreasele22

    Joined:
    Dec 5, 2018
    Posts:
    1
    Can you make a tutorial on how to do it using Windows 10? I tried following the tutorial but I didn't know where to find some stuff, and I was using the same layout.
     
  40. joshp5921

    joshp5921

    Joined:
    Dec 16, 2018
    Posts:
    1
    The canvas is displaying white lines along the X and Y axis that won't go away unless I disable the canvas.

    Canvas activated:
    upload_2018-12-15_19-54-46.png

    Canvas Deactivated:
    upload_2018-12-15_19-55-55.png

    And it isn't caused by either of the text layers:
    upload_2018-12-15_19-56-44.png

    What's the cause of this?

    Side-note: When I build and run the game I just get an empty sky-box :(
     
  41. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    8,752
    Click on the "Gizmos" button.
     
  42. richardtargett

    richardtargett

    Joined:
    Jan 8, 2019
    Posts:
    5
    I made the game, only problem is they dont get picked up and counted.
    It just has the player ball go through the gems in the ROLL A BALL
     
  43. The_Mango_Man

    The_Mango_Man

    Joined:
    Feb 6, 2019
    Posts:
    1
    Where do I SAVE it? I click the save button but it keeps saying 'file can only save in assets folder'.
     
  44. shane4roofie71

    shane4roofie71

    Joined:
    Feb 20, 2019
    Posts:
    5
    countText.text = "Count: " + count.ToString();
    if (count >= 12) it keeps throwing me an error on the = sign and says invalid token im a newbie please help

    This is the script i got so far
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine.UI;
    using UnityEngine;

    public class PlayerController : MonoBehaviour {
    public float speed;
    public Text countText;

    private Rigidbody rb;
    private int count;

    // Use this for initialization
    void Start () {
    rb = GetComponent<Rigidbody>();
    count = 0;
    SetCountText ();
    }

    // Update is called once per frame
    void Update () {

    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 ("");
    }
     
  45. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144

    You are correctly using an integer named count to store your count.
    You are incorrectly trying to convert an undeclared variable named Count to a string in your last line.
    you have: CountText.Text = " Count : " + Count.ToString ("");
    you want: CountText.Text = " Count : " + count.ToString ("");
    There may be other spelling errors (specifically capitalized/noncapitalized letters)
     
    shane4roofie71 likes this.
  46. shane4roofie71

    shane4roofie71

    Joined:
    Feb 20, 2019
    Posts:
    5
    hi i tryed your method and it still throwing the same error i tryed looking over my script and capitalized and non capapitalized
     
  47. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    From your description it sounds like the program does compile and execute, is that correct?
    It sounds like you can play it and pick up objects and see the score increase?
    I'm assuming that because you say "if (count >= 12) it keeps throwing me an error on the".
    If this is the case, it would help to know what the actual error says, but it could be that at this point in the execution your value in "count" is no longer a legal number, it is NaN (not a number). This is just pure guesswork.
    If that is the case, you could put a Try/Catch block around the code.
    Something like
    Code (CSharp):
    1. try
    2. {
    3.    CountText.Text = " Count : " + count.ToString ("");
    4. }
    5. catch
    6. {
    7.   CountText.Text = " Count : oops, there is an error. ";
    8. }
    But again, this is all just guessing
     
    shane4roofie71 likes this.
  48. shane4roofie71

    shane4roofie71

    Joined:
    Feb 20, 2019
    Posts:
    5
    upload_2019-3-3_18-52-2.png
     
  49. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    1 ) replace the semi-colon at the end of line 44 "void SetCountText ();" with an open curly bracket "void SetCountText () {" or, optionally put the open curly bracket on the next line.


    2) change line 45 to be:
    countText.Text = " Count : " + count.ToString ();
    (note lower case "c" in countText.Text)
    Also note that in line 45 of the image you posted, you still have an upper case "C" on the variable count that you are trying to convert to a string ("Count.ToString"). Note that the variable "Count" does not exists, the variable "count" does. Also, note that the ToString function doesn't need the enclosed quote signs ToString ("") , it will work fine as ToString ()

    3) add a semi-colon ; to the end of line 48 (... = "you win "; ) to terminate that statement

    4) add a closing curly bracket after line 48 to balance the opening one at line 47

    5) add a closing curly bracket after line 49 to balance the opening one you just added at line 44 (which now defines the complete "void SetCountText () {" method you've define here

    6) add a closing curly bracket at the bottom of the file to complete the class of this file you have near the top:
    public class PlayerController : MonoBehaviour {

    Note I am not near a compiler at the moment, I'm just winging it. There may be other things. Make the changes, read the errors. If you can't figure them out then post them and we'll try to help
     
    Last edited: Mar 5, 2019
    shane4roofie71 likes this.
  50. Alexane22

    Alexane22

    Joined:
    Mar 6, 2019
    Posts:
    2
    Hello, I have an issue on the RollBall Tutorial. I wrote the script like the tutorial but an error appear and I can't fix it ! It's CS 1061 about my vector3 :
    "Error CS1061 'Vector3' does not contain a definition for 'Player' and no accessible extension method 'Player' accepting a first argument of type 'Vector3' could be found (are you missing a using directive or an assembly reference?) "

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class CameraController : MonoBehaviour
    {
    public GameObject Player;

    private Vector3 offset;

    // Start is called before the first frame update
    void Start()
    {
    offset = transform.position - Player.transform.position;


    }

    // Update is called once per frame
    void LateUpdate()
    {

    transform.position = transform.position.Player + offset;
    }
    }

    What am I doing wrong ??
    Thans you,