I have a game object that when clicked, moves upwards a little, and rotates to demonstrate selection. I am trying to get it so that when I click the object again (deselect it), the object moves back down to the original way it was facing.
Moving the object down again is no problem, however I am having trouble getting the object to rotate, so that if faces the way it was originally facing. This is the latest code I have tried, however when I deselect the object it simply moves back down and keeps its new rotation.
public Transform originalRotationValue;
float rotationResetSpeed = 1.0f;
void Start () {
originalRotationValue = gameObject.transform;
}
void Update () {
//rotate selected piece
if(isSelected)
gameObject.transform.Rotate(0, 1, 0);
//otherwise rotate it back to its original rotation
else
transform.rotation = Quaternion.Slerp(transform.rotation, originalRotationValue.rotation, Time.time * rotationResetSpeed);
}
What am I missing/doing wrong?