unity 震动脚本_unity3D实现摄像机抖动特效

本文实例为大家分享了unity3D实现摄像机抖动的具体代码,供大家参考,具体内容如下

摄像机抖动特效 在需要的地方调用CameraShake.Shake()方法就可以

public class CameraShake : MonoBehaviour

{

///

/// The cameras to shake.

///

public List cameras = new List();

///

/// The maximum number of shakes to perform.

///

public int numberOfShakes = 2;

///

/// The amount to shake in each direction.

///

public Vector3 shakeAmount = Vector3.one;

///

/// The amount to rotate in each direction.

///

public Vector3 rotationAmount = Vector3.one;

///

/// The initial distance for the first shake.

///

public float distance = 00.10f;

///

/// The speed multiplier for the shake.

///

public float speed = 50.00f;

///

/// The decay speed (between 0 and 1). Higher values will stop shaking sooner.

///

public float decay = 00.20f;

///

/// The modifier applied to speed in order to shake the GUI.

///

public float guiShakeModifier = 01.00f;

///

/// If true, multiplies the final shake speed by the time scale.

///

public bool multiplyByTimeScale = true;

// Shake rect (for GUI)

private Rect shakeRect;

// States

private bool shaking = false;

private bool cancelling = false;

internal class ShakeState

{

internal readonly Vector3 startPosition;

internal readonly Quaternion startRotation;

internal readonly Vector2 guiStartPosition;

internal Vector3 shakePosition;

internal Quaternion shakeRotation;

internal Vector2 guiShakePosition;

internal ShakeState(Vector3 position, Quaternion rotation, Vector2 guiPosition)

{

startPosition = position;

startRotation = rotation;

guiStartPosition = guiPosition;

shakePosition = position;

shakeRotation = rotation;

guiShakePosition = guiPosition;

}

}

private Dictionary> states = new Dictionary>();

private Dictionary shakeCount = new Dictionary();

// Minimum shake values

private const bool checkForMinimumValues = true;

private const float minShakeValue = 0.001f;

private const float minRotationValue = 0.001f;

#region Singleton

///

/// The Camera Shake singleton instance.

///

public static CameraShake instance;

private void OnEnable()

{

if (cameras.Count < 1)

{

if (camera)

cameras.Add(camera);

}

if (cameras.Count < 1)

{

if (Camera.main)

cameras.Add(Camera.main);

}

if (cameras.Count < 1)

{

Debug.LogError("Camera Shake: No cameras assigned in the inspector!");

}

instance = this;

}

#endregion

#region Static properties

public static bool isShaking

{

get

{

return instance.IsShaking();

}

}

public static bool isCancelling

{

get

{

return instance.IsCancelling();

}

}

#endregion

#region Static methods

public static void Shake()

{

instance.DoShake();

}

public static void Shake(int numberOfShakes, Vector3 shakeAmount, Vector3 rotationAmount, float distance, float speed, float decay, float guiShakeModifier, bool multiplyByTimeScale)

{

instance.DoShake(numberOfShakes, shakeAmount, rotationAmount, distance, speed, decay, guiShakeModifier, multiplyByTimeScale);

}

public static void Shak

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值