zoukankan      html  css  js  c++  java
  • Unity3D相机震动效果

    在一些格斗、射击以及动作类游戏中

    相机震动效果是十分重要的

    一个平凡的镜头

    在关键时刻加入相机震动后

    便可以展现出碰撞、危险、打斗以及激动人心的效果

    相机震动的实现方式有很多

    但都会涉及摄像机位置的变化

    using System.Collections;
    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;
        // Use this for initialization
        void Start () {
            ThisTransform = GetComponent<Transform>();
        }
    
        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;
        }
    }

    使用时

    将此脚本挂到相机上

    然后在需要的时候开启协程即可

    StartCoroutine(Shake());
  • 相关阅读:
    捡来的一个大数模版。很好用
    小探catlan数
    hdu1060数学题求幂最左边的数
    食物相克
    工作 瓶颈 思路问题
    从用户态open到内核驱动实现
    内核代码 结构
    I2C原理
    asm
    man 2 3 5 普通命令(1) 函数库(3)
  • 原文地址:https://www.cnblogs.com/fws94/p/7510032.html
Copyright © 2011-2022 走看看