Im making a horror game and I have a torch. Its a Spot Light. I want a C# script that does the following: Move the light to where the mouse is when the right click button is down but dosent go too far away from the player.
var NewPos : Vector3;
var MoveAmount : float = 1;
var MoveSpeed : float = 2;
var MoveOnX : float;
var MoveOnY : float;
var DefaultPos : Vector3;
function Start(){
DefaultPos = transform.localposition;
}
function Update ()
{
MoveOnX = Input.GetAxis("Mouse X") * Time.deltaTime * MoveAmount;
MoveOnY = Input.GetAxis("Mouse Y") * Time.deltaTime * MoveAmount;
NewPos = new Vector3 (DefaultPos.x+MoveOnX, DefaultPos.y+MoveOnY, DefaultPos.z);
transform.localPosition = Vector3.Lerp(transform.localPosition, NewPos, MoveSpeed*Time.deltaTime);
if(Input.GetButtonDown("Fire2"))
{
ADS();
}
if(Input.GetButtonUp("Fire2"))
{
ADSOff();
}
}
function ADS()
{
DefaultPos = Vector3(0,0,1); //put your own values in
}
function ADSOff()
{
DefaultPos = Vector3(0.4,0,1.2); //put your own values in
}
Hope this works, just slap it on your torch and edit some values. should be all good!