Would someone please help me find this Null Reference Exception?
NullReferenceException: Object reference not set to an instance of an object
RespawnDieTrigger.OnTriggerEnter (UnityEngine.Collider hit) (at Assets/Troys Scripts/RespawnDieTrigger.js:17)
RespawnDieTrigger is the trigger script which is attached to the main game object(named Sphere) which is the following script. Below this script is my Respawn script which is attached to the first person controller (named FPS)
tum1-2 is the static trigger object(its a wall)
When the sphere hits the wall(tum1-2) the First Person Controller and all of its children(main camera and sphere) respawn perfectly. In my Hierarchy each time the sphere hits the wall(tum1-2) I see the FPS, FPS(Clone) FPS(Clone)(Clone)etc… The (Clone) just adds on to the end. So what I see in the Hierarchy after five collisions is FPS(Clone)(Clone)Clone)(Clone)(Clone).Just one FirstPerson Controller with five strings of (Clone) after it. Any Ideas why I’m getting this Null Reference Exception?
function OnTriggerEnter(hit:Collider){
if (hit.name == "tum1-2"){
// if player hit the wall...
Destroy(gameObject.Find("Main Camera"));
Destroy(gameObject);
Destroy(gameObject.FindWithTag("GameController"));
// it suicides
// get the object tagged "Respawn"
var objRespawn = GameObject.FindWithTag("Respawn");
// get the script RespawnScript.js
var script: RespawnScript = objRespawn.GetComponent(RespawnScript);
script.RespawnPlayer(); // respawn a new player
}
}
`
`
var playerPrefab: GameObject; // drag the player prefab here
function RespawnPlayer(){
Instantiate(playerPrefab, transform.position, transform.rotation);
}