i'm trying to set up an object that rotates randomly in a loop, but I can't seem to get it to work. This is what i have so far. I was hoping someone could help me this.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Spin : MonoBehaviour { [SerializeField] Transform[] waypoints;
[SerializeField]
float moveSpeed = 2f; int waypointIndex = 0; private Transform t;
// Use this for initialization void Start() { t = GetComponent(); RotateToRandomPosition(); randomRotation = waypoints[waypointIndex].randomRotation; } // Update is called once per frame void Update() { Rotate(); } void Rotate() { randomRotation = Vector3.randomRotation(Random, waypoints[waypointIndex].randomRotation, moveSpeed * Time.deltaTime); if (randomRotation == waypoints[waypointIndex].randomRotation) { waypointIndex += 1; } if (waypointIndex == waypoints.Length) waypointIndex = 1; } }
Answer by miguelrmonreal · Sep 03, 2018 at 05:57 AM
THis is what is looks like, the above didn't come out correctly.