Hi there,
Im still new in Unity,
I have a problem with a camera.
It is quite simple, im making a FPS and when I slide I would like the camera to move down a bit and to get back his position when the input is released. I dont know ho to access my Main Camera.
Usually FPS characters have the camera childed to them - you could change the camera’s transform.localPosition to shift its relative position. You can access the main camera with Camera.main, like this (script attached to any scene object - usually the character):
var offset: float = 0.1;
private var camTransf: Transform;
private var pos0: Vector3;
function Start(){
camTransf = Camera.main.transform;
pos0 = camTransf.localPosition;
}
function Update(){
var pos = pos0;
pos.y -= offset*Input.GetAxis("Vertical");
camTransf.localPosition = pos;
}
In this example, the main camera transform is saved in camTransf, and the camera is shifted down by an offset distance when the forward control is pressed, and is shifted up when going backwards.