On hover over object

I have a cool idea I am wanting to do but not sure how to do it. I the cube I have in my screen to rotate 90 degress when the mouse hovers over it. How would I start this? I have four different cubes I would like to do this. Each one only do it when I got over it.

Hi

you would create a script and attach it to all of the cubes.

In C# this would look something like this:

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    void OnMouseEnter() {
         transform.Rotate(Vector3.up * 90); // or whatever roatation you want
    }

    // to reset:
    void OnMouseExit() {
         transform.Rotate(*your inverse rotation*);
    }
}

hope it helps

-edited

over time:

void OnMouseOver() {
   Vector3 rotation = transform.rotation.eulerAngles;
   if(rotation.y < 90)
      rotation += new Vector3(0, rotation.y + 90 * Time.deltaTime, 0);
   transform.eulerAngles = rotation;
}

try this, it will rotate your object 90 degrees in one second. If you want it slower, decrease the angles. I didn’t test it :wink:

It sounds like you need to get more familiar with performing actions on hover and rotating the camera/screen.
OnMouseOver is the method that gets called on every frame that the mouse is over a collider, and OnMouseEnter is a method that is called when the mouse first enters a collider.
Camera.main accesses your main camera, and from there you can manipulate it’s transform (including rotation).