I need help with my gun swith statement (Look to the bottome of page):
#pragma strict
var EmptyInScene : GameObject;
var weapons : GameObject[] = new GameObject[4]; // Array of Weapons
private var curWeapon : GameObject;
function Start () {
}
function Update () {
if (Input.GetKeyDown("1")) ChangeWeapon(0);
if (Input.GetKeyDown("2")) ChangeWeapon(1);
if (Input.GetKeyDown("3")) ChangeWeapon(2);
if (Input.GetKeyDown("4")) ChangeWeapon(3);
}
function ChangeWeapon(weapon:int){
if(curWeapon){
Destroy(curWeapon);
}
var NewObject : GameObject = Instantiate(weapons[weapon], transform.position, transform.rotation);
NewObject.transform.parent = EmptyInScene.transform;
}
This works well but when I switch guns it doesn't destroy the current gun. I don't have any current gun coding. Should I make some or is there an easier way?
↧