I dont seem to get this right at all…
Im trying to get/make a script that does, so when you are in range of an object with an animation (like a door), you press like “D”, and the door should open (Play the animation).
I’ve had some help before, but it didnt seem to work.
Here is the script i got as help, which didnt work:
public class AnimationTest : MonoBehaviour
{
private Animation _anim;
private bool closeEnough = false;
void Start()
{
_anim = this.GetComponent<Animation>();
}
void Update()
{
if (Input.GetKeyDown("k") && closeEnough == true)
{
_anim.Play("Gate");
}
}
void OnGUI()
{
if (Vector3.Distance(targetObject.transform.position, player.transform.position) < desiredDistance)
{
GUI.Label(new Rect(10, 10, 200, 20), "[k]");
closeEnough = true;
}
}
}
And it would be nice having like a range of 5 or something.