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. Dismiss Notice

None of my scripts work.

Discussion in 'Scripting' started by Alec1998, Nov 17, 2014.

  1. Alec1998

    Alec1998

    Joined:
    Nov 10, 2014
    Posts:
    7
    I'm doing the Roll-a-Ball tutorial for a class I'm taking. A couple days ago, all of my scripts worked fine. I turn it on tonight, and none of them work. I haven't changed a thing, and I have no idea what happened. Any help?

    Player movement script
    Code (CSharp):
    1. using UnityEngine;
    2.     using System.Collections;
    3.  
    4. public class PlayerController : MonoBehaviour
    5. {
    6.     public float speed;
    7.  
    8.     void Update ()
    9.     {
    10.  
    11.     }
    12.  
    13.     void FixedUpdate ()
    14.     {
    15.         float moveHorizontal = Input.GetAxis ("Horizontal");
    16.         float moveVertical = Input.GetAxis ("Vertical");
    17.  
    18.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    19.  
    20.         rigidbody.AddForce (movement * speed * Time.deltaTime);
    21.     }
    22. }
    Camera follows player
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class CameraControl : MonoBehaviour
    5. {
    6.     public GameObject player;
    7.     private Vector3 offset;
    8.     // Use this for initialization
    9.     void Start ()
    10.     {
    11.         offset = transform.position;  
    12.     }
    13.    
    14.     // Update is called once per frame
    15.     void lateUpdate () {
    16.         transform.position = player.transform.position + offset;
    17.     }
    18. }
    19.  
    Script to make items rotate
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class rotation : MonoBehaviour {
    5.  
    6.     // Update is called once per frame
    7.     void Update () {
    8.         transform.Rotate (new Vector3 (15, 30, 45) * Time.deltaTime);
    9.     }
    10. }
    11.  
     
  2. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,066
    So when you say "None of my scripts work", what do you mean? You're getting errors? If so, what are the errors?
     
  3. Alec1998

    Alec1998

    Joined:
    Nov 10, 2014
    Posts:
    7
    No, that's just it. Nothing seems to be wrong. Unity and MonoDevelop tell me everything checks out fine. But when I try to test the game, though, nothing happens. The arrow keys don't move the player, the items don't rotate like they're supposed to, nothing.
     
  4. THoeppner

    THoeppner

    Joined:
    Oct 10, 2012
    Posts:
    205
    Maybe it helps to rebuild the whole project once again. Close Unity and delete the Library folder. That forces Unity to reimport all assets and compile the scripts once again.
     
  5. GetUpKidAK

    GetUpKidAK

    Joined:
    Apr 9, 2013
    Posts:
    84
    I assume the scripts are all attached to the correct gameobjects?
     
  6. Deleted User

    Deleted User

    Guest

    Are the public variables' values set in the inspector?
    In the first script, you have a 'speed' variable, but if it's 0 I'm guessing your character won't move.