Quantcast
Viewing all articles
Browse latest Browse all 41

On trigger and button input to enable/disable script

hello everyone, im tryin to make a script to attach on a gameobject that will find my player via tag and enable/disable the third person controller script on key press, i went on to do this by using nested ifs and it works but when i press the buttons i get null reference please help me!: var scriptname : ThirdPersonController; var Player : GameObject; function Start () { scriptname.enabled = false; } function OnTriggerStay (other : Collider) { if(other.gameObject.tag == "Player"){ if(Input.GetKeyDown("2")) { scriptname.GetComponent(ThirdPersonController).enabled = true; } } else if(Input.GetKeyDown("3")) { scriptname.GetComponent(ThirdPersonController).enabled = false; } }

Viewing all articles
Browse latest Browse all 41

Trending Articles