Hello everyone,
I currently have a “scope” GUI that plays when I push “fire2”, but at the same time, the rifle gameobject is attached to my player arms that play a mecanim animation (that simulates breathing). When I zoom in, the scope GUI does not move, but the weapon still does. How can I get my GUI to follow the mecanim’s movement? Or is there a way to stop the mecanim’s movements while zoomed in?
Thank you for your help.
Attached is the script I use to call the zoom function. (it is attached to a child component of the rifle gameobject.
var Gun : Transform;
var NexPos : float = 0.01;
var NextField : float = 40.0;
var NexPos2 : float = 0.0;
var dampVelocity : float = -0.4;
var dampVelocity2 : float = 0.4;
var dampVelocity3 : float = 0.4;
//for crosshairs
var crosshairtexture : Texture2D;
var positionCH : Rect;
static var chrosshairs :boolean = false;
function Update ()
{
var NewPos = Mathf.SmoothDamp(Gun.transform.localPosition.x, NexPos, dampVelocity, 0.3);
var NewField = Mathf.SmoothDamp(Camera.main.fieldOfView,NextField, dampVelocity2, 0.3);
var NewPos2 = Mathf.SmoothDamp(Gun.transform.localPosition.y, NexPos2, dampVelocity, 0.3);
Gun.transform.localPosition.x = NewPos;
Gun.transform.localPosition.y = NewPos2;
Camera.main.fieldOfView = NewField;
if (Input.GetButton("Fire2")) //Aims the gun
{
positionCH = Rect((Screen.width - crosshairtexture.width - 500), (Screen.height -crosshairtexture.height + 60), crosshairtexture.width, crosshairtexture.height);
chrosshairs = true;
//Brings the gun to center of screen
NextField = 10.0;
NexPos = -0.05;
NexPos2 = -0.05;
//slows down movement for camera
camera.main.GetComponent("MouseLook").sensitivityX = -5;
camera.main.GetComponent("MouseLook").sensitivityX = -5;
camera.main.GetComponent("MouseLook").sensitivityX = -5;
}
else
{
// resets gun position
NextField = 60.0;
NexPos = 0.0;
NexPos2 = 0.01;
chrosshairs = false;
//allows normal camera movement
camera.main.GetComponent("MouseLook").sensitivityX = 1;
camera.main.GetComponent("MouseLook").sensitivityX = 1;
camera.main.GetComponent("MouseLook").sensitivityX = 1;
}
}
function OnGUI()
{
if (chrosshairs == true)
{
GUI.DrawTexture(positionCH, crosshairtexture);
}
}