Hello unity people.
I am somewhat lost in a scripting part of a task i’ve been given. Basically its very simple, there is three buttons that control which one of three cameras who are active. I also have a script that makes an object always face a camera. When i change camera i want the “facing” script to change target camera to the active one, in other words make the object always face the active camera
There might be a very simple solution to this, but I have little to no experience in java coding and started my java “career”
yesterday. The attempts i’ve tried so far have turned out fruitless since I’m not to familliar with java structure or coding in general.
If anyone could point me in the right direction in how to complete this function, It would be much appreciated.
Camera button script
var camera1 : Camera;
var camera2 : Camera;
var camera3 : Camera;
var cube1 : GameObject;
var cube2 : GameObject;
var background : Texture2D;
function Start()
{
camera1.enabled = true; camera2.enabled = false; camera3.enabled = false;
cube1.renderer.enabled = false; cube2.renderer.enabled = false;
}
function OnGUI()
{
if (GUI.Button(Rect( 0, 718, 120, 50), "First person"))
{
camera1.enabled = false; camera2.enabled = true; camera3.enabled = false;
}
if (GUI.Button(Rect( 120, 718, 120, 50), "Birdseye"))
{
camera1.enabled = true; camera2.enabled = false; camera3.enabled = false;
}
if (GUI.Button(Rect( 240, 718, 120, 50), "Overview"))
{
camera1.enabled = false; camera2.enabled = false; camera3.enabled = true;
}
GUI.DrawTexture (Rect (0,0, background.width, background.height), background);
if (GUI.Button (Rect (830, 61, 70, 30), "", GUIStyle.none))
{
cube1.renderer.enabled = true;
}
if (GUI.Button (Rect (900, 61, 70, 30), "", GUIStyle.none))
{
cube1.renderer.enabled = false;
}
if (GUI.Button(Rect (830, 91, 70, 30), "", GUIStyle.none))
{
cube2.renderer.enabled = true;
}
if (GUI.Button(Rect (900, 91, 70, 30), "", GUIStyle.none))
{
cube2.renderer.enabled = false;
}
if (GUI.Button(Rect (830, 121, 70, 30), "", GUIStyle.none))
{
}
if (GUI.Button(Rect (900, 121, 70, 30), "", GUIStyle.none))
{
}
}
“Facing” script
var target : Camera;
function Update()
{
var n = target.transform.position - transform.position;
transform.rotation = Quaternion.LookRotation( n );
}
Thanks in advance. ![]()
Kim Larsson.