Hi, I’m trying to create a script that allows for the camera to move, on a button push, to a certain position, dictated by an empty Gameobject. The camera should be able to move in the x,y, and z directions. The only problem is, I want to be able to apply this script to multiple Groups that I imported from Google Sketchup. For example, when the button for group “A” is pushed, the camera moves to x position. On a second press of the button, the camera moves back to the starting position. But when I press the button for group “B”, the camera flashes for a second where it should be, then moves back to the original position without a second button press. Here’s the script for one group:
#pragma strict
private var outside1 : Transform;
private var originalspotTC : Transform;
private var moved = false;
static var main : Camera;
private var CameraBlack : Transform;
private var CameraStart : Transform;
private var BlackPicture : GameObject;
private var stringToEdit : String = "Some stuff";
function Start () {
originalspotTC = transform.Find("/originalTC");
outside1 = transform.Find("/Spot1");
CameraBlack = transform.Find("/CameraBlack");
CameraStart = transform.Find("/MainCameraStart");
BlackPicture = GameObject.Find("/BlackTexture");
}
function OnGUI () {
GUILayout.BeginHorizontal();
GUILayout.Space(200);
if(GUI.Button(Rect(50 , 50 , 150 , 50) , "Examine TC")){
if(moved){
moved = false;
BlackPicture.renderer.enabled = false;
}
else
{
moved = true;
}
}
GUILayout.EndHorizontal();
if(moved){
// moved is true
transform.position = outside1.position;
stringToEdit = GUI.TextArea (Rect (800, 100, 100, 100), stringToEdit, 200);
Camera.main.transform.position = CameraBlack.position;
BlackPicture.renderer.enabled = true;
The only issue I am having is with the camera position. Any help?