Now when I set the rotateText flag to true the object will rotate on the y and then when I set the rotateText flag to false the rotation will stop and the object will rotate back to it's original rotation.
but I want to add to it maybe using animationcurve and lerp or some other way ease in out for the rotation. so if the flag rotateText is true it will start slowly smooth to rotate to max rotation speed and when the flag is false it will slowly smooth rotate down to speed 0 until stop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class MyRotationTests : MonoBehaviour
{
public Text textName;
public float rotationSpeed;
public bool rotateText = false;
public string textToDisplay;
private Quaternion originalRotationValue;
private void Start()
{
textName.text = textToDisplay;
originalRotationValue = textName.transform.rotation;
}
private void Update()
{
Vector3 namePos = Camera.main.WorldToScreenPoint(this.transform.position);
textName.transform.position = namePos;
if(rotateText)
{
textName.transform.Rotate(Vector3.up, rotationSpeed * Time.deltaTime);
}
else
{
textName.transform.rotation = Quaternion.Slerp(textName.transform.rotation,
originalRotationValue,
Time.deltaTime * rotationSpeed);
}
}
}