- Home /
Timer triggered by tile?
How do I make a tile that triggers a timer when stepped on.
Can you provide any code you got, for example the Tile class?
public class teleport : $$anonymous$$onoBehavior { Public GameObject target; Transform target,$$anonymous$$ySpace;
Void Awake() { $$anonymous$$ySpace = transform; } Public void OnTriggerEnter(Collider other) { Switch (other name) { Case "teleporter": //this is my teleporter object on the scene gameObject.transform.position = Target_1.transform.position //Target_1 is a blue square on the scene// // if I step on the teleporter (the red square) it makes me go to the Target_1.position // } }
Remember that this script does what it needs to do fine.
But see where it teleports me? The GA$$anonymous$$EOBJECT.TRANSFOR$$anonymous$$.POSITION = TARGET_1.TRANSFOR$$anonymous$$.POSITION place? Right before that I want a timer that makes it not be teleport until 2 seconds passed. WHAT I DONT WANT IS the trigger to take 2 seconds to respond. I wanna step on it and EVEN if I walk of it the timer to the teleportation to still be ticking.
Answer by brunopava · Jun 25, 2015 at 06:05 PM
You can use this method:
http://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html
To create a simple timer you can use:
float time = 0;
private void Update()
{
time += Time.deltaTime;
Debug.Log(time);
}
ps: For the trigger to work properly you need to attach both collider and rigidbody to the object that is entering the trigger. As for the trigger itself you just need a collider with trigger enabled.
Your answer
![](https://koobas.hobune.stream/wayback/20220613201405im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
My high time score isn't working 1 Answer
Tilemaps making feature 1 Answer
Why do I get those green lines? 0 Answers
Raycast hits both objects 1 Answer
How to get a 2D polygonal sprite to collide with a Mesh Collider 1 Answer