亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Unity 中啟動粒子系統

在 Unity 中啟動粒子系統

C#
蝴蝶不菲 2022-10-15 15:13:13
(請原諒任何格式問題)我正在嘗試獲得一個簡單的粒子系統來使用 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 updatevoid Start(){    if (system != null)        Debug.Log("Trap found");}// Update is called once per framevoid 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);        }    }}}正如你所看到的,我有調試代碼報告粒子系統已經找到并且玩家對象確實與盒子碰撞器交互。粒子系統不播放。任何幫助將不勝感激。
查看完整描述

1 回答

?
慕妹3242003

TA貢獻1824條經驗 獲得超6個贊

如建議:

我的特殊問題的答案:“如何讓現有的 Unity ParticleSystem 通過腳本播放”(更具描述性的標題)。已解決。請注意,需要進一步研究才能了解答案為何有效。

ParticleSystem 中的一種設置稱為 Prewarm。啟用該設置允許 system.Play 和 system.Stop 代碼啟動和停止粒子系統。如前所述,我還不知道為什么將該設置更改為 true(啟用)允許代碼工作。

沒有進行適當的研究。我只是在玩設置,一次一個。


查看完整回答
反對 回復 2022-10-15
  • 1 回答
  • 0 關注
  • 168 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號