this is probably a frequently asked question, but i have used and tried 5 different scripts, all with the same result.
it not working.
if anyone knows a script please link it to me, because all i’m looking for, is a door that opens as soon as i touch a trigger.
i tried to make my own at one point:
var door : Transform;
function OnTriggerStay (other : Collider) {
var contact : String = other.transform.name;
if (contact == "Player"){
Destroy(door);
Destroy(other.gameObject);
}
}
its clear this doesn’t work either :I
First off, you probably don’t want to try and destroy the same things every frame.
But as MrThreepwood suggested, you need to make sure that you have colliders on things. Your player should have a collider and rigidbody, where as you door should have at least a collider whose Is Trigger box is checked. Then do something like this:
public GameObject door;
private int count;
void OnTriggerEnter(Collider other)
{
if (other.tag.Equals("Player"))
{
count++;
door.SetActive(false);
}
}
void OnTriggerExit(Collider other)
{
if (other.tag.Equals("Player") && --count < 1)
door.SetActive(true);
}
This will allow multiple players to enter the door collider area and will only close once all are out. Of course, for a single player game you can probably omit the counter.