Hi,
I’m still new to scripting, and am still learning.
But sometimes it strikes me hard.
So I want to trigger a door when the player hits the button, after that the door will open.
function OnTriggerEnter (other : Collider) {
var door = other.gameObject.Find("myDoor");
door.transform.position.y = 1;
}
This scripting is just fine.
So the next thing I want is that if the door is opened, it will close after a few seconds.
Here’s my idea.
Note: Instead of making it return to it’s original position, I just scripted Destroy because it’s easy to test with.
if(gameObject.Find("myDoor").transform.position.y >= 1) {
yield WaitForSeconds (3);
Destroy(gameObject.Find("myDoor"));
}
So this does nothing when I trigger the door. But if i set my ‘if’ comparison to >= 0, the door will be destroyed after 3 seconds. Because my door is at position y = 0.
So why doesn’t this work with >= 1?
Thanks in advance!