- Home /
speed doesn't decrease
Hello,
I made this script that simulates the spining of a... well, spining toy! The problem is that the spining speed never reaches zero. What is the problem?
#pragma strict
function Update () {
Spining();
}
function Spining () {
for(var rotSpeed : float = 1.0; rotSpeed >= -1.0; rotSpeed = rotSpeed - 0.1)
{
//Debug.Log(rotSpeed);
if(rotSpeed > 0.0)
{
transform.Rotate(0, rotSpeed, 0);
}
yield;
}
}
Answer by AcE_fLoOdEr · Jan 01, 2015 at 06:55 AM
Because you called the script in update. It would finish, stop. Then start over. It will never stop spinning. Use
function Start()
beware tho, it will stop instantly. Because for loops act fast. You will have to find a workaround.
Answer by ramp · Jan 01, 2015 at 08:14 PM
Hi , Use
StartCoroutine
StartCoroutine is not required to invoke a coroutine in UnityScript you can call a coroutine just like a regular function in UnityScript.
Your answer
![](https://koobas.hobune.stream/wayback/20220613175312im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
AddTorque in 2D doesn't work? 0 Answers
Rotate Around Object 2 Answers
Rotate player 360 degrees once 0 Answers
How can I make the gun rotate and shoot like lost control and shooting all around ? 0 Answers