Hi, I am a noob at Unity. I have a problem where I am trying to get my camera to move to a certain x,y,z location, but only after a button is pushed.Then when its pushed a second time, thecamera moves back to its original spot. The problem is, this button is created in a differnet script because it also tells an object where to move.
The script with the button:
#pragma strict
private var OutsideB: Transform;
private var OriginalspotB : Transform;
private var moved = false;
private var stringToEdit : String = "This is Black";
function Start () {
OriginalspotB = transform.Find("/Black-start");
OutsideB = transform.Find("/Black");
}
function OnGUI () {
GUILayout.BeginHorizontal();
GUILayout.Space(20);
if(GUI.Button(Rect(0,0,150,50), "Examine Black")){
if(moved){
moved = false;
}
else
{
moved = true;
}
}
GUILayout.EndHorizontal();
if(moved){
// moved is true
transform.position = OutsideB.position;
stringToEdit = GUI.TextArea (Rect (150, 175, 150, 50), stringToEdit, 20);
camera.main.fieldOfView=60;
}
else{
transform.position = OriginalspotB.position;
}
}
This code that I have started is for the camera, with a second button (that I don’t want)
#pragma strict
private var CameraB: Transform;
private var OriginalC: Transform;
private var moved = false;
function Start () {
OriginalC = transform.Find("/Main Camera Start");
CameraB = transform.Find("/CameraBlack");
}
function OnGUI () {
if(GUI.Button(Rect(0,50,150,50), "Examine Black")){
if(moved){
moved = false;
}
else
{
moved = true;
}
}
if(moved){
// moved is true
transform.position = CameraB.position;
}
else{
transform.position = OriginalC.position;
}
}
Any help on this?