We are doing a sniper game, and then to imitate a sniper mirror to open the breathing effect, that is, the sniper mirror will be up and down the gentle displacement, I refer to the online script and changed a bit, you can directly hang on your lens, and then put a sight in the middle of the screen, you can see the cool effect ~
public void Noise ()
{
Noisedeltax + = (((((((Mathf.cos (time.time) * Random.range (-nosiemaxrange, Nosiemaxrange)/5f) * nosiemaxspeed)-Noisedelta X)/100);
Noisedeltay + = (((((((Mathf.sin (time.time) * Random.range (-nosiemaxrange, Nosiemaxrange)/5f) * nosiemaxspeed)-Noisedelta Y)/100);
Rotationxtemp + = (Noisedeltax * breathholderval);
Rotationytemp + = (Noisedeltay * breathholderval);
RotationX + = ((Rotationxtemp-rotationx)/3);
RotationY + = ((rotationytemp-rotationy)/3);
if (RotationX >= 360)
{
RotationX = 0;
rotationxtemp = 0;
}
if (RotationX <=-360)
{
RotationX = 0;
rotationxtemp = 0;
}
RotationX = Clampangle (RotationX,-180, 180);
RotationY = Clampangle (RotationY,-60, 60);
Rotationytemp = Clampangle (rotationytemp,-60, 60);
quaternion xquaternion = Quaternion.angleaxis (RotationX, vector3.left);
quaternion yquaternion = Quaternion.angleaxis (RotationY, Vector3.forward);
transform.localrotation = transform.localrotation * xquaternion * yquaternion;
}
static float Clampangle (float angle, float min, float max)
{
if (angle <= -360.0f)
Angle + = 360.0f;
if (angle >= 360.0f)
Angle-= 360.0f;
return Mathf.clamp (angle, Min, max);
}
Unity Day One Technical point (16)---sniper mirror breathing effect