I am trying to make a compass system and I have a script that is able to rotate objects to look at other objects, however when trying to use this script with the new GUI. To rotate the compass point to a specific object, it does not rotate the GUI image. It appears to flip the image 90 degrees on the Y-axis and then it is frozen in that place. I have also noticed though, that you cannot rotate UI elements when paused, so is there no way to set it the new GUI to rotate in real time?
Here is the script:
using UnityEngine;
using System.Collections;
public class LookTowardsSpecifiedTarget : MonoBehaviour
{
public GameObject objectToLookAt;
void Update()
{
if (objectToLookAt != null) {
Vector3 v = objectToLookAt.transform.position - transform.position;
v.x = v.z = 0.0f;
transform.LookAt (objectToLookAt.transform.position - v);
transform.Rotate (0, 180, 0);
}
}
}
↧