zoukankan      html  css  js  c++  java
  • unity3d笔记:控制特效的播放速度

           一般在游戏中,主角或者怪物会受到减速效果,或者攻击速度减慢等类似的状态。本身动作减速的同时,衔接在角色上的特效也需要改变相应的播放速度。一般特效有三个游戏组件:

     

    关键点就是改变Animator,Animation和Particle System的Speed这个速度变量。就可以随意的控制特效的播放速度了。

    代码如下:

    using UnityEngine;
    using System.Collections;
    
    public class EffectSpeedControl : MonoBehaviour
    {
    
       
        public float time = 1;//销毁时间
        float mSpeed = 1f;//播放时间
    
        void Start()
        {
    
            ChangeSpeed(transform);
        }
        void ChangeSpeed(Transform tr)
        {
    
            if (tr.animation != null)
            {
                foreach (AnimationState an in tr.animation)
                {
                    an.speed = mSpeed;
                }
            }
            Animator ani = tr.GetComponent<Animator>();
            if (ani != null)
            {
                ani.speed = mSpeed;
            }
            if (tr.particleSystem != null)
            {
                tr.particleSystem.playbackSpeed = mSpeed;
            }
            for (int i = 0; i < tr.childCount; i++)
            {
                ChangeSpeed(tr.GetChild(i));
            }
    
        }
        
        public float Speed
        {
            get
            {
                return mSpeed;
            }
            set
            {
                mSpeed = value;
                ChangeSpeed(transform);
            }
        }
        void Update()
        {
            time -= Time.deltaTime * mSpeed;
            if (time < 0)
            {
                Destroy(this.gameObject);
    
            }
        }
    }
    
  • 相关阅读:
    C++ std::stack 基本用法
    linux6 安装 ntopng
    linux 6安装 redis2.6
    Linux6搭建Tomcat服务器
    EXSI6.5忘记root密码
    python3笔记--数字
    python3笔记--运算符
    python3基本数据类型
    python3笔记
    centos6.X升级python3.X方法
  • 原文地址:https://www.cnblogs.com/CodeFaker/p/4449028.html
Copyright © 2011-2022 走看看