using UnityEngine;
using System.Collections;
public class Clickvalve : MonoBehaviour
{
// From the inspector, add the player GameObject on this script's field
public Transform Player;
// Exact same thing as player
public Transform Box;
// Set the desired interaction distance value
public float InteractionDistance = 10;
// Setting up the "playing" variable
bool playing;
// Setting up a public variable to be referenced by another script later
public static int Valvepressure = 10;
//following section updates every single frame
void Update()
{
//if the animation is playing...
if (GetComponent<Animation>().IsPlaying("Valve_turnright"))
{ //...then set "playing" to true
playing = true;
}
else //otherwise...
{ //...set it to false.
playing = false;
}
}
//now, when I press the mouse button...
void OnMouseDown()
{ //Playerdist is defined as the distance between player and box
float Playerdist = Vector3.Distance(Box.position, Player.position);
//then if the player distance is less than the interaction distance and the animation isnt playing...
if (Playerdist < InteractionDistance & !playing);
{// it should do all this. and it does...but for some reason, it skips the if statement.
GetComponent<Animation>().Play("Valve_turnright");
GetComponent<AudioSource>().Play();
if (Valvepressure > -6)
{
Valvepressure = Valvepressure - 1;
}
Debug.Log("Valve pressure is now" + Valvepressure + "!");
}
}
}