Search Unity

Assistance Required: Roller-Ball Introduction - "Unexpected Symbol"

Discussion in 'Scripting' started by insaneasabucket, Nov 27, 2014.

  1. insaneasabucket

    insaneasabucket

    Joined:
    Nov 27, 2014
    Posts:
    5
    Hello there. I am new and just starting Unity. I am taking the code from part two of the course by I seem to have ran into an error I cannot decipher. The problem is "float". Apparently it is an unexpected symbol. Why it is puzzles me.

    using UnityEngine;
    using System.Collections;

    public class PlayerController:MonoBehaviour
    {
    public float speed;
    void FixedUpdate()
    {
    float moveHorizontal = Input.GetAxis ("Horizontal")
    float moveVertical = Input.GetAxis ("Vertical")

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

    Rigidbody.AddForce(movement * speed * Time.deltatime);
    }
    }

    Unless I'm missing a bracket here or there I'm not quite sure what to make of the situation. How dumb am I at this right now?
     
  2. Skorn

    Skorn

    Joined:
    Oct 31, 2014
    Posts:
    22
    Missing a semi-colon here at the end. And the two lines before that.
    Code (csharp):
    1. Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    That's the only error that I see.
     
    Last edited: Nov 27, 2014
    insaneasabucket likes this.
  3. christinanorwood

    christinanorwood

    Joined:
    Aug 9, 2013
    Posts:
    402
    The two lines before that need semi-colons too.
     
    insaneasabucket likes this.
  4. insaneasabucket

    insaneasabucket

    Joined:
    Nov 27, 2014
    Posts:
    5
    Thank you guys! Hope I wasn't a bother!
     
  5. insaneasabucket

    insaneasabucket

    Joined:
    Nov 27, 2014
    Posts:
    5
    Uhm, I seem to have encountered another problem after adding the semicolons.

    "Assets/Roller/Scripts/PlayerControler.cs(14,43): error CS0120: An object reference is required to access non-static member `UnityEngine.Rigidbody.AddForce(UnityEngine.Vector3, UnityEngine.ForceMode)'"
     
  6. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    You wrote 'Rigidbody' instead of 'rigidbody'.
    The first one is the name of the class. What you wanna use in this case is the second one. It references an instance of the Rigidbody class if there is a Rigidbody attached to the gameObject. If not, it will be 'null'', the literal for reference types witch basically means 'i do not reference any instance of this class'.
     
    insaneasabucket likes this.
  7. insaneasabucket

    insaneasabucket

    Joined:
    Nov 27, 2014
    Posts:
    5
    Ah. I can't believe I thought it would work with a capital.
    Forgive me, I have a terrible habit of using capitals. Thank you so much for the information! I'm beginning to see what I need here and there.
     
  8. insaneasabucket

    insaneasabucket

    Joined:
    Nov 27, 2014
    Posts:
    5
    "The referenced script on this Behaviour is missing!"
    Anyone know why? I've looked up and at most I've found a few solutions involving loading an empty scene and bringing everything in, or using a "FindMissingScripts" script.