- Home /
Question by
geryc123 · Jan 20, 2014 at 01:22 AM ·
function updatescroll view
How to turn this script?
I have a script to scroll:
var speed = 2.2;
var crawling = false;
function Start()
{
Screen.showCursor = true;
}
function Update ()
{
if (!crawling)
return;
transform.Translate(Vector3.up * Time.deltaTime * speed);
if (gameObject.transform.position.y > .8)
{
crawling = true;
}
}
And I have one questions, how to do after 10 seconds began to scroll in down ?
I have tried:
var speed = 2.2;
var crawling = false;
function Start()
{
Screen.showCursor = true;
}
function Update ()
{
if (!crawling)
return;
transform.Translate(Vector3.up * Time.deltaTime * speed);
if (gameObject.transform.position.y > .8)
{
crawling = true;
}
yield WaitForSeconds(10);
if (!crawling)
return;
transform.Translate(Vector3.down * Time.deltaTime * speed);
if (gameObject.transform.position.y > .8)
{
crawling = true;
}
}
but this is not work :/
Comment
Answer by robertbu · Jan 20, 2014 at 01:28 AM
You cannot yield in Update(). I might approach this problem differently, but from where you are now, consider using Invoke(). You could do:
var speed = 2.2;
var crawling = false;
function Start()
{
Screen.showCursor = true;
Invoke("Reverse", 10.0);
}
function Reverse()
{
speed = -speed;
}
function Update ()
{
if (!crawling)
return;
transform.Translate(Vector3.up * Time.deltaTime * speed);
if (gameObject.transform.position.y > .8)
{
crawling = true;
}
}
Ok. $$anonymous$$oves to 10 seconds up and stops but not moved down.
Ok I removed
crawling = false;
and work. Thank You :)
Your answer