using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Turn_Move : MonoBehaviour {
public int TurnX;
public int TurnY;
public int TurnZ;
public int MoveX;
public int MoveY;
public int MoveZ;
public bool World;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (World == true) {
transform.Rotate(TurnX * Time.deltaTime,TurnY * Time.deltaTime,TurnZ * Time.deltaTime, Space.World);
transform.Translate(MoveX * Time.deltaTime, MoveY * Time.deltaTime, MoveZ * Time.deltaTime, Space.World);
}else{
transform.Rotate(TurnX * Time.deltaTime,Random.Range(3,300) * Time.deltaTime,TurnZ * Time.deltaTime, Space.Self);
transform.Translate(MoveX * Time.deltaTime, MoveY * Time.deltaTime, MoveZ * Time.deltaTime, Space.Self);
}
}
}
This is the random part :
Random.Range(3,300)
but sine it's changing the random numbers too quick the changes are almost not visible. I want somehow to make that if for example the next random will stay for example 5 seconds at this speed number then move to the next random number and again stay at this number 5 seconds and so on.
Tried this :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Turn_Move : MonoBehaviour {
public int TurnX;
public int TurnY;
public int TurnZ;
public int MoveX;
public int MoveY;
public int MoveZ;
public bool World;
private bool IsGameRunning = false;
// Use this for initialization
void Start ()
{
IsGameRunning = true;
StartCoroutine(SpeedWaitForSeconds());
}
// Update is called once per frame
void Update () {
}
IEnumerator SpeedWaitForSeconds()
{
var delay = new WaitForSeconds(3);//define ONCE to avoid memory leak
while (IsGameRunning)
{
if (World == true)
{
transform.Rotate(TurnX * Time.deltaTime, TurnY * Time.deltaTime, TurnZ * Time.deltaTime, Space.World);
transform.Translate(MoveX * Time.deltaTime, MoveY * Time.deltaTime, MoveZ * Time.deltaTime, Space.World);
}
else
{
transform.Rotate(TurnX * Time.deltaTime, Random.Range(3, 300) * Time.deltaTime, TurnZ * Time.deltaTime, Space.Self);
transform.Translate(MoveX * Time.deltaTime, MoveY * Time.deltaTime, MoveZ * Time.deltaTime, Space.Self);
}
yield return delay;//wait
}
}
}
but that just rotate the object once each 3 seconds. and not rotating it all the time with speed changing every 3 seconds.
but now it's not rotating for 3 seconds it rotating every 3 seconds.
better to describe what I want is like intervals. The object should spin all the time nonstop like i Update but then each 3 seconds to change for a random speed.
for example spin at speed 5 ....after 3 seconds spin at speed 77 ....after 3 second spin at speed 199