Wednesday, May 24, 2017

unity - How do I wait to execute code?


I'm trying to make a relatively simple elevator (which essentially teleports the player), but I don't want it to instantly teleport them. I want the player to enter the collider, wait 2-3 seconds, and then do it to take make it seem somewhat more natural.


My code thus far:


using UnityEngine;
using System.Collections;


public class Teleporter : MonoBehaviour
{
public GameObject TeleportTo;
//public Material NewSkybox;

void TimerInvoke()
{

}


void OnTriggerEnter(Collider other)
{

Vector3 displacement = other.transform.position - this.transform.position;

other.transform.position = TeleportTo.transform.position;
other.transform.position += displacement;

//RenderSettings.skybox = NewSkybox;
}

}

Also if possible I'd like to stray away from coroutines. How should I do this?




No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...