Im trying to make a simple script that will allow the player to open treasure chests within the map(using C# and Unity3d). The chests are opened using a simple if statement:
void Update(){
if (Input.GetKey(KeyCode.E))
{
anim.Play("Open Chest");
}
}
and I’d like to know if there’s a way to modify the if statement to include some sort of detection
to see if the player character is within range.
With the code I have now pressing E opens ALL ten chests I have placed on the terrain; is there a better way to script for range other than creating a new script for each specific chest?