Im building an arena styled shotoer game, where you have to pick up weapons in order to have them activated in the player.
All the weapons are initially in the players inventory, but they are all set to be inactive. The player has 9 boolean values that determine if they have the weapon in their inventory, by having it set to true, so they can only be selected if the boolean is equal to true. The weapon pickup is supposed to activate this boolean, by seeking the weapon in the players inventory by seeking its tag. here's the script,
var gun : GameObject;
var myself : GameObject;
var player : GameObject;
var thetag : String;
var gunname : String;
var ammo : gunswitcher;
var isweapon1 : boolean = false;
var isweapon2 : boolean = false;
var isweapon3 : boolean = false;
var isweapon4 : boolean = false;
var isweapon5 : boolean = false;
var isweapon6 : boolean = false;
var isweapon7 : boolean = false;
var isweapon8 : boolean = false;
var isweapon9 : boolean = false;
var deadtime : float = 30;
var x : float = 0;
var y : float = 0.25;
var z : float = 0;
function OnTriggerEnter() {
gun.SetActive(true);
activate();
turnoff();
}
function turnoff() {
collider.enabled = false;
myself.SetActiveRecursively(false);
yield WaitForSeconds(deadtime);
collider.enabled = true;
myself.SetActiveRecursively(true);
}
function Update()
{
player = GameObject.FindWithTag("Player");
ammo = player.GetComponent(gunswitcher);
transform.Rotate(x, y, z);
gun = GameObject.Find(gunname);
}
function activate() {
if(isweapon1 == true){
ammo.gunactive1 = true;
}
else if(isweapon2 == true){
ammo.gunactive2 = true;
}
else if(isweapon3 == true){
ammo.gunactive3 = true;
}
else if(isweapon4 == true){
ammo.gunactive4 = true;
}
else if(isweapon5 == true){
ammo.gunactive5 = true;
}
else if(isweapon6 == true){
ammo.gunactive6 = true;
}
else if(isweapon7 == true){
ammo.gunactive7 = true;
}
else if(isweapon8 == true){
ammo.gunactive8 = true;
}
else if(isweapon9 == true){
ammo.gunactive9 = true;
}
}
the gun GameObject is the gun it's supposed to find, myself is the pickups model,(which is working and is fine) the player is the players GameObject in the scene, (also works) thetag is the tag of the gun that it's supposed to find, and ammo is the script that allows for the guns to be swapped, and has the boolean values.(the script finds this correctly too.)
the isweapon bools in this script determine which gun is supposed to be activated when it's picked up.
The problem with the script, is that at line 48, it doesn't find the gun with the predetermined gun object. I don't know why it isn't finding it.
the turnoff function isn't the problem, I thought that may be relevant to mention.
↧