• unity震动效果


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    //思想:在短时间内在规定圆内随机震动对象位置,从而实现震动效果
    public class CamZhengDong : MonoBehaviour {
        //震动对象属性
        private Transform Tr = null;
        //
        public float zhenDongShiJian = 6.0f;
        //震动幅度
        public float fuDu = 10.0f;
        //震动对象移动速度
        public float speed = 2.0f;
        
        // Use this for initialization
        void Start () {
            Tr = GetComponent<Transform>();
            StartCoroutine(CamShake());
        }
    
    
        //private void Update()
        //{
        //    if (ElapsedTime < ShakeTime) {
        //        Vector3 RanPoint = OrigPosition + Random.insideUnitSphere * ShakeAmount;
        //        Tr.localPosition = Vector3.Lerp(Tr.localPosition, RanPoint, Time.deltaTime * speed);
        //        //计时
        //        ElapsedTime += Time.deltaTime;
        //    }
        //}
    
        public IEnumerator CamShake() {
            float jishi = 0.0f;
            Vector3 OrigPosition = Tr.localPosition;
            while (jishi < zhenDongShiJian) {
                //Random.insideUnitSphere单位圆内随机数
                Vector3 RanPoint = OrigPosition + Random.insideUnitSphere * zhenDongShiJian;
                Tr.localPosition = Vector3.Lerp(Tr.localPosition,RanPoint,Time.deltaTime * speed);
                yield return null;
                //计时
                jishi += Time.deltaTime;
            }
        }
    
    }
  • 相关阅读:
    [loj6484]LJJ爱数书
    [loj3163]动态直径
    [loj2983]数树
    [luogu3785]文本校正
    [loj2572]字符串
    [loj3103]节日庆典
    [atARC118F]Growth Rate
    [atARC118E]Avoid Permutations
    [cf794G]Replace All
    [cf756E]Byteland coins
  • 原文地址:https://www.cnblogs.com/Prode/p/10002093.html
Copyright © 2020-2023  润新知