I would like to enable my switchWeapon script when i pick up my m4 but i have his error "NullReferenceException: Object reference not set to an instance of an object
PickUpM4.Update () (at Assets/Scripts/PickUpM4.js:14)
"
#pragma strict
var soundPlayer : GameObject;
private var showGUI : boolean = false;
var M4 : GameObject;
private var mym4 : GameObject;
function Start () {
}
function Update () {
if(showGUI == true){
if(Input.GetKeyDown("e")){
gameObject.GetComponent(SwitchWeapon).enabled = true;
M4.SetActive(true);
Destroy (gameObject);
Instantiate (soundPlayer, transform.position, transform.rotation);
}
}
}
function OnTriggerEnter(hit : Collider){
if(hit.gameObject.tag =="Player"){
showGUI = true;
}
}
function OnTriggerExit(hit : Collider){
if(hit.gameObject.tag =="Player"){
showGUI = false;
}
}
function OnGUI(){
if(showGUI == true){
GUI.Box(Rect(Screen.width/2-100,Screen.height/2-12.5,200,25), "[e] Rammaser Munition M4A1");
}
}