Unity ACT游戏相机逻辑

MipMap:用于在远离摄像机时降低图片质量的功能,因此对于UI上的贴图都可以关闭,以减少内存占用。

CamSlowMotionDelay:慢动作

Time.timeScale = slowMotionTimeScale;

CamShake:震动效果

Vector3 rand = new Vector3(getRandomValue(), getRandomValue(), getRandomValue());
scale *= multiplier;
float t = 0;
while (t < time) {
	if (randomize) {
		transform.localPosition = new Vector3 (camShakeX.Evaluate(t) * scale * rand.x, camShakeY.Evaluate(t) * scale * rand.y, camShakeZ.Evaluate(t) * scale * rand.z);				
	} else {
		transform.localPosition = new Vector3 (camShakeX.Evaluate(t) * scale, camShakeY.Evaluate(t) * scale, camShakeZ.Evaluate(t) * scale);
	}

	t += Time.deltaTime / time;
	yield return null;
}
transform.localPosition = Vector3.zero;

CameraFollow:相机跟随

public Transform target;                         // 目标点 
	[Header ("Follow Settings")]
	public float distanceToTarget = 5;               // 到目标的距离
    public float heightOffset = 5;                   // 相机相对于目标的高度偏移量
    public float viewAngle = 10;                     // 向下旋转
    public Vector3 AdditionalOffset;                 // 额外偏移量
    public bool FollowZAxis;                         // 启用或禁用z轴以下的相机

    [Header ("Damp Settings")]
	public float DampX = 3f;                         // X方向的偏移量
	public float DampY = 3f;                         // Y方向的偏移量
	public float DampZ = 3f;                         // Z方向的偏移量

	[Header ("View Area")]
	public float MinLeft;                            // 左侧边界
	public float MaxRight;                           // 右侧边界

	[Header ("Wave Area collider")]
	public bool UseWaveAreaCollider;                 // 是否使用锁屏
	public BoxCollider CurrentAreaCollider;          // 锁屏节点对象
	public float AreaColliderViewOffset;             // 锁片边界差值
	void Update () {
		if (target){

			//initial values
			float currentX = transform.position.x;
			float currentY = transform.position.y;
			float currentZ = transform.position.z;
			Vector3 playerPos = target.transform.position;

			//Damp X
			currentX = Mathf.Lerp(currentX, playerPos.x, DampX * Time.deltaTime);

			//DampY
			currentY = Mathf.Lerp(currentY, playerPos.y - heightOffset, DampY * Time.deltaTime);

			//DampZ
			if (FollowZAxis) { 
				currentZ = Mathf.Lerp (currentZ, playerPos.z + distanceToTarget, DampZ * Time.deltaTime);
			} else {
				currentZ = distanceToTarget;
			}

			//Set cam position
			if(CurrentAreaCollider == null) UseWaveAreaCollider = false;
			if (!UseWaveAreaCollider) {
				transform.position = new Vector3 (Mathf.Clamp (currentX, MaxRight, MinLeft), currentY, currentZ) + AdditionalOffset;
			} else {
				transform.position = new Vector3 (Mathf.Clamp (currentX, CurrentAreaCollider.transform.position.x + AreaColliderViewOffset, MinLeft), currentY, currentZ) + AdditionalOffset;
			}

			//Set cam rotation
			transform.rotation = new Quaternion(0,180f,viewAngle,0);
		}
	}

你可能感兴趣的:(UNITY)