I’m not sure how this happened, but my script randomly stopped working. It’s supposed to let you break some wood off a door when you get to a certain distance, but no matter how much I increase the distance value it only lets me open it when I’m right in front of it. If anyone can help me fix this I would be really grateful.
Here’s The Script:
public float TheDistance;
public GameObject ActionDisplay;
public GameObject Wood;
public AudioSource Crack;
public GameObject Trigger;
public GameObject Trigger2;
void Update()
{
TheDistance = PlayerCasting.DistanceFromTarget;
}
void OnMouseOver()
{
if (TheDistance <= 4f)
{
ActionDisplay.SetActive(true);
}
if (Input.GetButtonDown("Action"))
{
if (TheDistance <= 4f)
{
ActionDisplay.SetActive(false);
Wood.SetActive(false);
Crack.Play();
Trigger2.SetActive(true);
Trigger.SetActive(false);
}
}
}
void OnMouseExit()
{
ActionDisplay.SetActive(false);
}