Looking at a Object for 5 Seconds then Teleport
Hi All,
I like to have this function in unity: Look at an Object (e.g. a Cube) and after 5 sec. i should be teleported to another plane. Is this possible? I was searching for anything like this but can´t find it.
Thank you in advance.
Answer by X10KND · Nov 22, 2016 at 12:45 PM
You can make a bool that check whether you are looking at the object or not. If true, then a countdown starts, at the end of which you teleport.
Something like this :
bool isLooking = false;
float countdown = 5;
void Update () {
isLooking = //Script to check if you are looking
if(isLooking) {
countdown -= Time.deltaTime;
}
if(!isLooking) {
countdown = 5;
}
//Teleport if countdown reaches zero
if(countdown <= 0) {
transform.position = new Vector3 (/*Teleport position*/);
}
}
Let me know if it works.
Hey, thanks for your reply. If i use your code the object is teleported, but i want to be teleported to another place (Vektor).
Thank you in advance.
Hi you can copy the code into your GoogleVr main camera or the main camera and get teleported to any point you define in the code after 5 seconds. I think pedram92 wants to know sth about: He is standing on a plane with 2-3 cubes, he is looking on the specific cube for 5 seconds and then he gets teleported to another plane in the scene? For this he needs a script that detects the looking on the cube. On googlevr you have a rectangle asset. How can we do a looking script?
Let me explain it in detail: I have for example an Cube called "Cube" if i look at this cube for 5 seconds, i want to be teleported to another place. So that it has to be dependend to where i look at the moment where i am going. $$anonymous$$aybe with some if statements...