Even if I set the value 1 on the y only on the spinAxis variable and leave both x and z 0 it will spin also on the x and z.
How can I make the objectToSpin to spin only on the y axis ?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MissleLauncherRotation : MonoBehaviour
{
public GameObject objectToSpin;
public Vector3 spinAxis;
public float timeToSpin = 5f;
public float spinSpeed = 20f;
public bool randomSpin = false;
private void Start()
{
StartCoroutine("Spin");
}
private void Update()
{
}
IEnumerator Spin()
{
float spinTimer;
while (true)
{
if (randomSpin == true)
{
spinAxis = Random.onUnitSphere;
}
spinTimer = timeToSpin;
while (spinTimer > 0f)
{
objectToSpin.transform.Rotate(spinAxis, Time.deltaTime * spinSpeed);
spinTimer -= Time.deltaTime;
yield return null;
}
}
}
}