Hi, i want to move my camera in my scene based on key press( A - for left side movement, D - for Right side movement) and with some speed. If i want to move towards right i.e in X Axis i should move it with selected speed like 5,10 etc and delta time. If i give speed as 5 then camera should move 5 units towards right or left based on key which is pressed.( i.e if camera is at (0,0,15) it should be at (5,0,15) at one shot if i press A) and if i give speed as 10 it should move 10 units at one shot. My problem is if i give threshold value i,e if i want to translate camera from position (0,0,15) to (7,0,15) with speed 5 and i press key A it will move to (5,0,15) on 1st attempt and i should restrict camera not to move more than 7 on its X Axis on 2nd attempt. Plz help me to achieve it.
//Program
var CamPos : float;
var Speed : float;
function Start()
{
CamPos = camera.main.transform.position.x;
Speed = 5.0;
}
function Update()
{
if(Input.GetKeyDown(Keycode.A))
{
if(camera.main.transform.pos.x <= 7)
{
camera.main.transform.translate(Vector3.left * Time.deltaTime * Speed);
}
}
}
If i do like this camera is moving towards left but how can i restrict it not to move move than (7,0,15) and how to move camera 5 units on one shot key press,Plz help me