i have a problem, i want to make a switchweapon script.
heres my working code that i am using:
var weapons: GameObject[];
private var curWeapon: int = 0; // now curWeapon is an int!
var shots: GameObject[];
private var curShot: int = 0;
function ChangeWeapon(weapon:int){
curWeapon = weapon;
for (var i = 0; i < weapons.length; i++){
weapons*.SetActiveRecursively(i == weapon);*
}
}
function ChangeShot(weapon:int){
curShot = weapon;
for (var i = 0; i < shots.length; i++){
shots*.SetActiveRecursively(i == weapon);*
}
}
function Update(){
if (Input.GetKeyDown(“1”)){
ChangeWeapon(0);
ChangeShot(0);
}
if (Input.GetKeyDown(“2”)){
ChangeWeapon(1);
ChangeShot(1);
}
if (Input.GetKeyDown(“3”)){
ChangeWeapon(2);
ChangeShot(2);
}
}
but theres the problem: i want to switch a weapon by pressing “E” when colliding with a weapon in the world.
help please