Rotate cube as if it were floating in the sea

Hello, dear community!

I’m trying to make a cube seem floating on a surface, I’ve found a script here:
http://answers.unity3d.com/questions/822484/a.html

     public Vector3 from = new Vector3(0f, 0f, 135f);
     public Vector3 to   = new Vector3(0f, 0f, 225f);
     public float speed = 1.0f; 
     
     void Update() {
         float t = Mathf.PingPong(Time.time * speed * 2.0f, 1.0f);
         transform.eulerAngles = Vector3.Lerp (from, to, t);
         
     }

It works great! But it only “lerps” between 2 vectors. Is it possible to lerp between 4 or 5 different cube rotations? The help is appreciated!

EDIT:
I’ve tried writing the following script, but it doesn’t work: “Cannot implicitly convert float to int” in the “transform.eulerAngles = Vector3.Lerp (fromarrays[randomnumber1from], toarrays[randomnumber2to], t);”

using UnityEngine;
using System.Collections;

public class rotation12 : MonoBehaviour {
	
		public Vector3 from = new Vector3(0f, 0f, 135f);
		public Vector3 to   = new Vector3(0f, 0f, 225f);

		public Vector3 from2 = new Vector3(0f, 0f, -100f);
		public Vector3 to2   = new Vector3(0f, 0f, 100f);
		public Vector3 from3 = new Vector3(0f, 0f, -200f);
		public Vector3 to3   = new Vector3(0f, 0f, 200f);
		public Vector3 from4 = new Vector3(0f, 0f, -300f);
		public Vector3 to4   = new Vector3(0f, 0f, 300f);

		public Vector3[] fromarrays;
		public Vector3[] toarrays;

		public float randomnumber1from;
		public float randomnumber2to;

		public float speed = 1.0f; 
		
	void Start(){
		fromarrays[0]=from;
		fromarrays[1]=from2;
		fromarrays[2]=from3;
		fromarrays[3]=from4;

		toarrays [0] = to;
		toarrays [1] = to2;
		toarrays [2] = to3;
		toarrays [3] = to4;
	}

	void Update() {
	
		rotatefuncrion ();
	}

	void rotatefuncrion(){
		float t = (Mathf.Sin (Time.time * speed * Mathf.PI * 2.0f) + 1.0f) / 2.0f;
		randomnumber1from = Random.Range (0, 3);
		randomnumber2to = Random.Range (0, 3);
		transform.eulerAngles = Vector3.Lerp (fromarrays[randomnumber1from], toarrays[randomnumber2to], t);
	}
		
}

Could use suggest what is the reason?

Your error is due to the fact that you declared randomnumber1from, and randomnumber2to, as float. If you want to use them to index into an array, you must declare them as int.

“Is there a way to stop Random.Range till previous Lerp is done?” Well, the parameter you pass to Lerp should be a value between 0 and 1. When it reaches 1, the Lerp could be considered “done” as it has reached the “to” Vector. In this case, I would compare t>0.95 in-case of rounding/timing problems

Worth noting, that since you are passing a cyclical sine wave, you might consider it “done” after a full “cycle”, rather than simply when the value reaches 1. In this case, you will need to remember what “t” value your “cycle” started on, and wait till “t” it gets close to that number again. (create & use a class member variable to store this value, so it remains “in-scope” across multiple calls to update().)