I’ve got this script. It seemed to work fine when it was js and half worked fine until I combined it for one GUI script. Can anyone tell me what’s wrong? The code is supposed to take two objects and show the xyz distance between them. Then on the click of a button switch between two cameras.
using UnityEngine;
using System.Collections;
public class GUIPos : MonoBehaviour
{
public GameObject cam1;
public GameObject cam2;
public Transform Controller;
public Transform Target1;
private bool Alter;
private float x;
private float z;
private float y;
void OnGui ()
{
//Coordinates display
GUI.Label (new Rect(10, 20, 85, 25), "x");
Frame=Controller.position.x/4-Target1.position.x/4;
GUI.Label (new Rect(100, 20, 60, 25), x.ToString("#.00"));
GUI.Box (new Rect(10, 70, 85, 25), "Outboard");
z=Controller.position.z-Target1.position.z;
GUI.Box (new Rect(100, 70, 60, 25),z.ToString("#.00"));
GUI.Box (new Rect(10, 120, 85, 25), "Elevation");
y=Controller.position.y-Target1.position.y;
GUI.Box (new Rect(100, 120, 60, 25), y.ToString("#.00"));
//camera switch code
cam2.transform.position = new Vector3(200f, 100f, 200f);
if (GUI.Button(new Rect(10, 370, 50, 30), "Click to Switch View"))
{
Alter = cam1.active;
cam1.active =! Alter;
cam2.active = Alter;
}
}
}