Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

NullReferenceError - This code is from unity's tutorial page ( Tnx for the help )

$
0
0
using UnityEngine; using System.Collections; public class prime_script : MonoBehaviour { public GameObject ref_object; // temp1 and temp2 are references to the other script private sec_script temp1; private tert_script temp2; private BoxCollider boxCol; void Awake () { temp1 = GetComponent(); temp2 = ref_object.GetComponent(); boxCol = ref_object.GetComponent(); } void Start () { boxCol.size = new Vector3(8,8,8); Debug.Log("The player's score is " + temp1.playerScore); Debug.Log("The player has died " + temp2.numberOfPlayerDeaths + " times"); } } using UnityEngine; using System.Collections; public class sec_script : MonoBehaviour { public int playerScore; void Awake() { playerScore = 9001; } } using UnityEngine; using System.Collections; public class tert_script : MonoBehaviour { public int numberOfPlayerDeaths; void Awake() { numberOfPlayerDeaths = 3; } } // the sec_script and tert_scripts are attached to a cube ; and i have manually assigned the ref_object of prime_script as the cube. While playing the size of the box collider is increasing but their is nothing on the log. Its showing :- NullReferenceException: Object reference not set to an instance of an object prime_script.Start () (at Assets/Scripts/prime_script.cs:30)

Viewing all articles
Browse latest Browse all 2891

Trending Articles