(请原谅任何格式问题)我正在尝试获得一个简单的粒子系统来使用 OnTriggerEnter 并停止使用 OnTriggerExit。遵循粒子系统上的 Unity API ( https://docs.unity3d.com/ScriptReference/ParticleSystem.Play.html )。我开发了以下代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Electric_Trap_Trigger : MonoBehaviour
{
ParticleSystem system
{
get
{
if (_CachedSystem == null)
_CachedSystem = transform.GetChild(0).gameObject.GetComponent<ParticleSystem>();
return _CachedSystem;
}
}
private ParticleSystem _CachedSystem;
public bool includeChildren = true;
//Start is called before the first frame update
void Start()
{
if (system != null)
Debug.Log("Trap found");
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "Player")
{
Debug.Log("Trap Triggered by: " + other.gameObject.tag);
if(system != null)
{
system.Play(includeChildren);
}
}
}
private void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "Player")
{
Debug.Log("Trap Exited by: " + other.gameObject.tag);
if (system != null)
{
system.Stop(includeChildren);
}
}
}
}
正如你所看到的,我有调试代码报告粒子系统已经找到并且玩家对象确实与盒子碰撞器交互。粒子系统不播放。任何帮助将不胜感激。
蝴蝶不菲
慕妹3242003
随时随地看视频慕课网APP
相关分类