- Home /
Changing the camera when clicked on a collider
How do I change the position of my camera when i click on a collider. This is for a 3D menu. Do I use a trigger?
What have you got working already? I would use a normal collider, and raycasts. $$anonymous$$oving the camera is easy- but you need to know where to move it to.
Only this var cam1:GameObject; //Assign Camera 1 var cam2:GameObject; //Assign Camera 2 var cam3:GameObject; //Assign Camera 3 var cam4:GameObject; //Assign Camera 4
Then i dont know what to do. Since i am really new to scripting
Some basics..
Do you really need all these cameras? This makes it a bit trickier, as you need to either remove unwanted audio listeners or turn them off and on constantly on corresponding cameras(you can only have one audio listener active at a time).
First things first, your camera(s) should be type Camera, not GameObject.
var cam1:Camera;
There is the main camera(default camera when making a new scene), which you can refer to in code by using
Camera.main;
The position of your camera will be handled by Vectors. Ex. Vector3 for x,y, and z positions.
var cameraPosition1:Vector3;
Like syclamoth said, you can do a raycast(Physics.Raycast) to see if you're clicking on something. Theres a bit more work to do though...
Check out the http://unity3d.com/support/documentation/ScriptReference/index.html>Unity Script Reference, as this will give you examples of how the code is used. Hope this helps get you started.