- Home /
Is there a yield WaitForSeconds type code for the update?
Is there a yield WaitForSeconds type code for the update? if not, what could i use?
Answer by tanoshimi · Nov 10, 2013 at 03:58 PM
Update() is your main game loop - the lifeblood of your game. It runs every frame and can't be interrupted or paused. Suitable alternatives for yield WaitForSeconds
really depend on what you're trying to achieve, but, assuming it's something like "Wait 5 seconds, then execute myfunction()", then what you're looking for is:
Invoke("myfunction", 5);
http://unity3d.com/learn/tutorials/modules/beginner/scripting/invoke
ok I was just wondering if there was a way to pause inside an if statement. maybe I should have specified. Invoke and
function myCustomFunction();
is what i use all the time to pause my stuff. just looking for an alternative
for JS not c#
Why do you need an alternative? What does Invoke() not do for you? Do you mean pause the game? If so, you're looking for Time.timeScale.
im probably asking the wrong questions lol. The project that i am working on requires me to interchange models at the same positions and when i click on one of the models; I want it to start moving underneath the map. The inter changing happens in the update when i click it using:
my$$anonymous$$odel[0].position = Vector(0,0,0);
i Guess my question would be is how do i make my models move underneath the map for a specific amount of time and then move its position back to the POOLING postion at (0,1000,0);($$anonymous$$inda like a reset Position) Thanks!
import System.Collections.Generic;
private var PoolingPositonHeight = 1000;
private var yRotation1 = -90;
private var yRotation2 = 0;
private var UpRotation = -90;
var AllObjects: Transform[];
private var NU$$anonymous$$_$$anonymous$$ediumCommericalBuildings = 76;
private var $$anonymous$$ediumC_New_NA$$anonymous$$E = "$$anonymous$$ediumCommerical_N";
private var $$anonymous$$ediumC_Damaged_NA$$anonymous$$E = "$$anonymous$$ediumCommerical_D";
private var $$anonymous$$ediumC_Collapsed_NA$$anonymous$$E = "$$anonymous$$ediumCommerical_C";
var $$anonymous$$ediumCommerical_N : Transform;
var $$anonymous$$ediumCommerical_D : Transform;
var $$anonymous$$ediumCommerical_C : Transform;
private var $$anonymous$$ediumCommericalBuildings_N: Transform[];
private var $$anonymous$$ediumCommericalBuildings_D: Transform[];
private var $$anonymous$$ediumCommericalBuildings_C: Transform[];
function Update() {
if (Input.Get$$anonymous$$ouseButtonDown(1)){
Reset();
}
if (Input.Get$$anonymous$$ouseButtonDown(0)) {
var hit: RaycastHit;
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, hit)) {
if (hit.collider.gameObject.name == "$$anonymous$$ediumCommerical_N_0"){
$$anonymous$$ediumCommericalBuildings_N[0].position = Vector3(0,PoolingPositonHeight,0);
$$anonymous$$ediumCommericalBuildings_D[0].position = Vector3(-84.77094,3.168458,132.8046);
$$anonymous$$ediumCommericalBuildings_D[0].rotation = Quaternion.Euler(Vector3(UpRotation, yRotation1, 0));
}else if(hit.collider.gameObject.name == "$$anonymous$$ediumCommerical_D_0"){
$$anonymous$$ediumCommericalBuildings_D[0].position = Vector3(0,PoolingPositonHeight,0);
$$anonymous$$ediumCommericalBuildings_C[0].position = Vector3(-84.77094,3.168458,132.8046);
}}}
this is rather lengthy but this is what i have in my script This script in interchanging three building types at the same position. I want to click on the second building and have it move underneath the map like it is sinking. how would i achive this in the update based on a time?
Answer by ohlin · May 13, 2015 at 10:56 AM
sry heres what i was looking for.
var timer : float = 0.0; // begins at this value
var timerMax : float = 3.0; // event occurs at this value
function Update()
{
timer += Time.deltaTime;
if (timer >= timerMax)
{
Debug.Log("timerMax reached ! put what you want to trigger in here.");
//or set a variable so you can put an if your variable jibberjabber
//somewhere else.
}
}