- Home /
Question by
twotostudio · Sep 30, 2020 at 02:13 PM ·
coroutinetimegravity
Decrease the gravity in half for 10 seconds
void gravdown()
{
StartCoroutine(downgrav());
}
private IEnumerator downgrav()
{
//codes
}
I have a button. And when this button is pressed, the current gravity value has to be halved for a time like 10 seconds and then return to its original state. When I did some research on how to do this, I came across coroutine. But "IEnumerator downgrav ()" I get an error in this part. CS0161 '': not all code paths return a value coroutine ". Since it's something I've never used before, I don't know what to do. How can I do what I want?
Comment
Best Answer
Answer by andrew-lukasik · Sep 30, 2020 at 04:24 PM
private IEnumerator downgrav ()
{
Vector3 initialGravity = Physics.gravity;
Physics.gravity = initialGravity * 0.5f;
yield return new WaitForSeconds( 10f );
Physics.gravity = initialGravity;
}
Answer by N-8-D-e-v · Sep 30, 2020 at 04:12 PM
If you are getting that error then change the coroutine to a method, you are not using anything from a coroutine