unity3d - 统一粒子系统问题
问题描述
我正在制作一款赛车游戏,并且希望在您越野时有岩石从轮胎上飞出。我遇到的问题是粒子系统没有在应该触发的时候触发。我用它作为地面来触发一个 bool 并且 bool 可以很好地触发。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GroundEffect : MonoBehaviour
{
public void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Player"))
{
other.transform.root.GetComponentInChildren<KartController>().isOnGround = true;
}
}
public void OnTriggerExit(Collider other)
{
if (other.gameObject.CompareTag("Player"))
{
other.transform.root.GetComponentInChildren<KartController>().isOnGround = false;
}
}
}
奇怪的是,调试日志会触发,但粒子系统不会。我试过把它全部放在地面脚本下,我把它放在“!isOnBoostStrip”下的“isOnGround”下,即使加速交换工作粒子我也没有试过没有“p.Stop( );" 只是让它不循环,仍然没有运气,尽管当我这样做时它做了一件奇怪的事情,它会开火,但只有当我碰到障碍物时才会开火。
非常感谢任何帮助,我不确定我哪里出错了。
编辑:在这个视频中,我展示了我当前的岩石系统和默认粒子系统的平面设置和错误。它还只检查“IsOnGround”是否为真,这似乎工作得很好。这是视频 - https://www.youtube.com/watch?v=P6TfacNZZxE 这是我在视频中使用的代码。
void Update()
{
//Follow Collider
transform.position = sphere.transform.position - new Vector3(0, 0.4f, 0);
if (!isOnBoostStrip)
{
//Accelerate
if (Input.GetButton("Fire1"))
{
speed = curAccel;
}
//Reverse
if (Input.GetButton("Fire2"))
{
speed = -curAccel / 3;
}
if (!isOnGround)
{
curAccel = zAcceleration;
}
if (isOnGround)
{
curAccel = zAcceleration / 2;
}
}
else if (isOnBoostStrip)
{
speed = zAcceleration * boostStripSpeed;
foreach (ParticleSystem p in exhaustParticles)
{
if (!isDrifting)
{
c = turboColors[0];
}
var pmain = p.main;
pmain.startColor = c;
p.Play();
}
}
//Rocks
if (isOnGround)
{
foreach (ParticleSystem p in groundParticles)
{
Debug.Log(isOnGround);
p.Play();
}
}
}
解决方案
Unity 的粒子系统有时可能有点不稳定,我相信您现在已经发现了。我过去使用的一个解决方案是将麻烦的粒子系统设置为Play on Awake
. 然后不使用粒子上的Play
and ,而是使用Stop
粒子的GameObject,SetActive
分别使用true和false。
推荐阅读
- artifactory - 如何在不重启 Artifactory 的情况下重启 SHA256MigrationJob?
- android - 如何在android模块中使用全局变量
- php - 我想按列对表格进行排序包含标签(HTML标签)
- angular - 有没有办法在 Zeppelin 中获取 Angular 到 Spark 的变量形式
- android - 更新房间数据库中的数据并更新视图后 BLE 连接突然失败
- android - Firebase FCM 使用 Ionic3 Cordova 推送通知
- powershell - office 365通过powershell批量添加共享邮箱成员
- jquery - 用 jquery 填充 html 表数据失败 Uncaught ReferenceError
- javascript - 如何使用引导程序 4 警报?
- elasticsearch - 如何将 ElasticSearch 命令翻译成 NEST 并使其具有幂等性