unity技能粒子特效追踪

技能追踪

技能追踪其实就是让粒子系统追着敌人打,也就是移动粒子,要想移动粒子要把一个物体上的粒子全部拿到,然后遍历移动,

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour {
    public GameObject A;
    private float speed = 50;
    private ParticleSystem particle;
    private int size;
    private ParticleSystem.Particle[] temp;
   
    void Start() {
        particle = this.GetComponentInChildren<ParticleSystem>();
        temp = new ParticleSystem.Particle[particle.maxParticles];
       
    }
    void LateUpdate()
    {
      size=particle.GetParticles(temp);
        float step = speed * Time.deltaTime;
        for(int i = 0; i < size; i++)
        {
            temp[i].position = Vector3.MoveTowards(temp[i].position, A.transform.position, step);
  A.transform.position, step);
        }
        particle.SetParticles(temp,size);
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。