unity特效播放实现步骤
- 把特效拉到要播放特效的物体下面
- 特效有
Particle System
组件,在代码中获取ParticleSystem _mShootParticleSystem = GunBarrelEnd.GetComponentInChildren<ParticleSystem>();
- 在合适的时候设置播放位置
ParticleSystem.transform.position = Vector3 position
,并播放ParticleSystem.Play()
例子如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shooting : MonoBehaviour
{
//开枪特效
private ParticleSystem _mShootParticleSystem;
// Start is called before the first frame update
void Start()
{
_mShootParticleSystem = GameObject.Find("GunBarrelEnd").GetComponentInChildren<ParticleSystem>();
}
void Update()
{
Shoot(transform.position);
}
public void Shoot(Vector3 position)
{
_mShootParticleSystem.transform.position = position;
_mShootParticleSystem.Play();
}
}
来源:CSDN
作者:胜天半子_王二_王半仙
链接:https://blog.csdn.net/qq_40666620/article/details/104694061