The following is the code I’m using. I have no other script that has ChangeRotation as a variable that clashes with this one.
using UnityEngine;
using System.Collections;
public class RandomMovement : MonoBehaviour {
public float rotationSpeed;
public float movementSpeed;
public float ChangeRotation;
public float rotationTime;
void ChangeRotation()
{
if(Random.value > 0.5f)
{
rotationSpeed = -rotationSpeed;
}
Invoke(ChangeRotation,rotationTime);
}
void Start()
{
Invoke(ChangeRotation,rotationTime);
}
void Update() {
transform.Rotate (new Vector3 (0, 0, rotationSpeed * Time.deltaTime));
transform.position += transform.up*movementSpeed*Time.deltaTime;
}
}