vendredi 25 décembre 2015

My Unity Script Wont work?

Hi I have a script attached to the main camera, and in this script I want to choose a number between 0 to 5 . And depending on what number I get, I want a script to run. Hers my script that is attached to the main camera. I keep getting this error

NullReferenceException: Object reference not set to an instance of an object RandomFunction.Start () (at Assets/Resources/Scripts/RandomFunction.cs:22)

using UnityEngine;
   using System.Collections;
   public class RandomFunction : MonoBehaviour {
     int n;
     void Awake()
     {
         GetComponent<RandomFunction> ().enabled = true;
     }
     void Start () 
     {
         n=Random.Range(0,5);
         if(n==0)
         {
             GetComponent<BlueGoUp> ().enabled = true;
         }
         else if(n==1)
         {
             GetComponent<RedGoUp> ().enabled = true;
         }
         else if(n==2)
         {
             GetComponent<GreenGoUp> ().enabled = true;
         }
         else if(n==3)
         {
             GetComponent<OrangeGoUp> ().enabled = true;
         }
         else if(n==4)
         {
             GetComponent<YellowGoUp> ().enabled = true;
         }
         else if(n==5)
          {
             GetComponent<PurpleGoUp> ().enabled = true;
         }
     }

 }




Aucun commentaire:

Enregistrer un commentaire