- Home /
how to move my camera...
Hello guys
I'm just practising with unity and creating very easy scripts. I have created a Camera.. named MyCamera. So I want to move it.. once I clicked a button in my GUI. So I created... my js script... declared my button in my OnGUI function. now: in the OnGUI I declared:
theCamera = GetComponent("MyCamera");
and to change it I thought to use:
theCamera.transform.Translate(Vector3(0,10,0)); but... Unity returns me a message that It's not possible to access an object in this way...so... any suggestion? :)
Many thanks. Giancarlo
Answer by Tuti · Aug 20, 2010 at 10:25 PM
Instead of:
theCamera = GetComponent("MyCamera");
use
theCamera = Camera.main.gameObject;
Answer by freeclup · May 25, 2013 at 08:21 PM
add this code to camera script
if (Input.GetKey (KeyCode.UpArrow)) { handPlay = GameObject.Find("gol"); // name your object
var psx= handPlay.transform.position.x;
var psy= handPlay.transform.position.y;
var psz= handPlay.transform.position.z;
var TellCamNextLocation2 : Vector3 = Vector3 (psx,500, psz);
Camera.mainCamera.transform.position = TellCamNextLocation2 ;
transform.position=TellCamNextLocation2;
}
Your answer
Follow this Question
Related Questions
Problems Scripting a Camera 1 Answer
RPG scripts 2 Answers
vector3.forward doesn't work when used in Rigidbody? 2 Answers
Moving the Camera Up and Down by pressing Key 2 Answers
Camerascript works strange! 0 Answers