鸟语天空
摄像机震动效果
post by:追风剑情 2019-5-5 20:12

示例

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraShake : MonoBehaviour
{
    private Transform ThisTransform = null;

    public float ShakeTime = 2.0f;
    public float ShakeAmount = 3.0f;
    public float ShakeSpeed = 2.0f;

    void Start()
    {
        ThisTransform = transform;
        StartCoroutine(Shake());
    }

    public IEnumerator Shake()
    {
        Vector3 origPosition = ThisTransform.localPosition;
        float ElapsedTime = 0.0f;

        while (ElapsedTime < ShakeTime)
        {
            Vector3 RandomPoint = origPosition + Random.insideUnitSphere * ShakeAmount;
            ThisTransform.localPosition = Vector3.Lerp(ThisTransform.localPosition, RandomPoint,
                Time.deltaTime * ShakeSpeed);
            yield return null;
            ElapsedTime += Time.deltaTime;
        }

        ThisTransform.localPosition = origPosition;
    }
}

运行测试

2.gif

评论:
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容