I want my game object to look at me when I hover over it with the mouse, but I can’t get it to work how I want. Instead of waiting until I hover, each of the gameobjects I attached the script to look at me right when I start it up. Here is my script:
using UnityEngine;
using System.Collections;
public class hoverScript : MonoBehaviour {
public Transform target;
public string levelToLoad;
public AudioClip soundhover;
public AudioClip beep;
public int rotationSpeed;
public bool QuitButton = false;
public bool onHover = false;
private Transform myTransform;
//On Startup
void Awake() {
myTransform = transform;
}
void OnMouseEnter() {
audio.PlayOneShot( soundhover);
onHover = true;
}
void OnMouseUp() {
audio.PlayOneShot( beep);
if( QuitButton) {
Application.Quit();
}
else {
Application.LoadLevel( levelToLoad);
}
}
// Update is called once per frame
void Update () {
if( onHover = true) {
//look to camera
myTransform.rotation = Quaternion.Slerp( myTransform.rotation, Quaternion.LookRotation( target.position - myTransform.position), rotationSpeed * Time.deltaTime);
}
}
}
I’m guessing it has something to do with the booleans, but I can’t figure it out. If someone else could help I would really appreciate it!