After I press the c key to crouch and I’m within the box collider of the enemy apc I don’t want the health to go down as I would be “hidden”, it works. And if I start the game and walk to the apc without crouching or pressing c once my health goes down so that works as well.
But if I press c once at the beginning when I’m not within the enemy collider and then move towards the apc it still says “player is hidden” when I’m not hidden, all i did was press c once at the beginning. In other words if I press c once I’m always hidden but I only want to be hidden when I’m close to the apc.
Here is my script (I tried adding an activation boolean variable so only if hidden is true AND I’m in box collider I shoudl get a message displaying hidden but it’s not working or updating
var health : float = 5.0;
var spawn : boolean = false;
var activation : boolean = false;
function OnTriggerEnter (player : Collider) {
activation = true;
Debug.Log("acivation is" + activation);
if (player.gameObject.CompareTag ("Player"))
{
var playerScript : run = player.GetComponent(run);
if (playerScript.hidden == true activation == true)
{
Debug.Log("apc has not detected you");
}
else
{
health = health - 1;
Debug.Log("apc has detected you " + health);
spawn = true;
}
}
}
function LateUpdate()
{
if (spawn) //if player dies reset back all the player info
{
//gameObject.Find("fps").transform.position = Vector3(150,80,160);
health = 5.0;
spawn = false;
hidden = false;
}
}
and I’m calling the hidden from another script called run here
if (Input.GetKey("c")){ // press C to crouch
h = 0.5 * height;
speed = crchSpeed; // slow down when crouching
hidden = true;