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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Roll a Ball

Discussion in 'Community Learning & Teaching' started by meteoros, Mar 19, 2015.

Thread Status:
Not open for further replies.
  1. meteoros

    meteoros

    Joined:
    Mar 19, 2015
    Posts:
    15
    Hi,on video tutorial about "moving the player" i create the script as in video but when in unity says that something is obsolete and changes the code on Line 15
    Original code
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class PlayerController : MonoBehaviour
    6. {
    7.     // Use this for initialization
    8.     void FixedUpdate ()
    9.     {
    10.         float moveHorizontal = Input.GetAxis("Horizontal");
    11.         float moveVertical = Input.GetAxis("Vertical");
    12.  
    13.         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    14.  
    15.         rigidbody.AddForce(movement);
    16.     }
    17. }
    18.  
    Code after changes
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class PlayerController : MonoBehaviour
    6. {
    7.     // Use this for initialization
    8.     void FixedUpdate ()
    9.     {
    10.         float moveHorizontal = Input.GetAxis("Horizontal");
    11.         float moveVertical = Input.GetAxis("Vertical");
    12.  
    13.         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    14.  
    15.         GetComponent<Rigidbody>().AddForce(movement);
    16.  
    17.     }
    18. }
    19.  
    and when at unity at the bottom says"
    MissingComponentException: There is no 'Rigidbody' attached to the "Main Light" game object, but a script is trying to access it.
    You probably need to add a Rigidbody to the game object "Main Light". Or your script needs to check if the component is attached before using it.
    UnityEngine.Rigidbody.AddForce (Vector3 force) (at C:/buildslave/unity/build/artifacts/generated/common/modules/NewDynamics.gen.cs:706)
    PlayerController.FixedUpdate () (at Assets/Scripts/PlayerController.cs:14)" any ideias what is happening? Thanks
     
  2. Socrates

    Socrates

    Joined:
    Mar 29, 2011
    Posts:
    787
    My first thought from that error is that you put the PlayerController script onto your Main Light instead of onto your player object. The player object has a rigidbody component, but the light would not.

    Or you put the script on both objects. Either way, first thing would be see what scripts are on the Main Light and make sure.
     
    NOONE_ and meteoros like this.
  3. meteoros

    meteoros

    Joined:
    Mar 19, 2015
    Posts:
    15
    The PlayController script is in the right place, i did every thing from the begining and i forgot to add the rigidyBody component to the Player(sphere).Thank you for your help and time Socrates.
     
  4. meteoros

    meteoros

    Joined:
    Mar 19, 2015
    Posts:
    15
    Roll-a-Ball - Collecting and Counting - 05 - Roll-a-ball - Unity Official Tutorials
    I'm geting an error after i create the colision script (Player-->pickup)when i go to unity i get this error:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class PlayerController : MonoBehaviour
    6. {
    7.     public float speed;
    8.  
    9.     void FixedUpdate()
    10.     {
    11.         float moveHorizontal = Input.GetAxis ("Horizontal");
    12.         float moveVertical = Input.GetAxis ("Vertical");
    13.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    14.         GetComponent<Rigidbody>().AddForce (movement * speed * Time.deltaTime);
    15.     }
    16.     void OnTriggerEnter(Collider other)
    17.     {
    18.         if (other.GameObject.tag == "Pickup")
    19.         {
    20.             other.GameObject.SetActive(false);
    21.         }
    22.     }
    23. }
    24.  
    Assets/Scripts/PlayerController.cs(19,31): error CS1061: Type `UnityEngine.Collider' does not contain a definition for `GameObject' and no extension method `GameObject' of type `UnityEngine.Collider' could be found (are you missing a using directive or an assembly reference?)

    after this i select the "Pickup" prefab and go to add tag, but in tag, my list is empty, i've an option with a "+" and "-" sign to add a tag, when i add a tag it gives only the option to give a name to it, in the video(7:14m) i see 2 fields "size" and "Element 0", any ideias how to fix this?
     
    Last edited: Mar 20, 2015
  5. meteoros

    meteoros

    Joined:
    Mar 19, 2015
    Posts:
    15
    the first problem is solved it's "gameObject" with a small letter g...any ideias how to solve the tag issue?
     
  6. Socrates

    Socrates

    Joined:
    Mar 29, 2011
    Posts:
    787
    I am not certain I understand what you are asking here, so I'm going to just walk through how to add a new tag. These images are from Unity 5, so if you are using Unity 4 it may look a little different.

    1) Select the object you want to tag.
    2) Near the top of the Inspector where it shows Tag, click on "Untagged".
    upload_2015-3-20_17-50-16.png
    3) Choose "Add Tag...".
    4) You will now see a list of tags you have defined for your project. If you have not defined any tags yet, it will say "List is Empty".
    upload_2015-3-20_17-50-4.png
    5) Click on the + sign, which will give you a new field to fill in.
    upload_2015-3-20_17-51-6.png
    6) Fill in the name of the tag you want.


    You can also access the project tags through Edit -> Project Settings -> Tags and Layers.
     
    meteoros likes this.
  7. meteoros

    meteoros

    Joined:
    Mar 19, 2015
    Posts:
    15
    it's solved..Thank you
     
  8. meteoros

    meteoros

    Joined:
    Mar 19, 2015
    Posts:
    15
    Displaying text - 06 - Roll-a-ball - Unity Official Tutorials
    I'm using unity 5.0,in the tutorial(2:18m) says to add "GUI Text" but in "GameObject" menu i dont see any "GUI Text",any ideias where it is?
     
  9. meteoros

    meteoros

    Joined:
    Mar 19, 2015
    Posts:
    15
    i just found the answer in the unity manual:

    To add a GUIText component in Unity 5.0, first useGameObject->Create Empty to create an empty game object, then use the Component->Rendering->GUIText option to add the GUIText component to the newly created game object. If the text isn’t visible when you press Play, check that the transform has suitable position, typically (0.5, 0.5, 0.0).
     
  10. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    meteoros likes this.
Thread Status:
Not open for further replies.