Unity车辆选择场景粒子、HP扣减及敌方销毁问题求助
Unity游戏开发故障排查
- 选择蓝色车辆时,所有粒子特效异常触发播放
- 撞击敌方车辆后,敌方未按预期触发爆炸特效并被销毁
- 除初始车辆外,其余车辆撞击障碍物(如Crate)时HP扣减逻辑不生效
此前所有功能运行正常,重装电脑后出现以上问题。已自行检查代码并借助ChatGPT排查,未发现代码层面问题;尝试在Start方法中添加private void Start() { Smoke.Stop(); Explosion.Stop();}代码,仍无法解决问题。
相关控制代码如下:
public class PlayerControl : MonoBehaviour { private float speed = 20.0f; private float turnSpeed = 30.0f; private float horizontalInput; private bool Won = false; private bool gameover = false; public int Health = 100; public ParticleSystem Smoke; public ParticleSystem Dust; public ParticleSystem Dust2; public ParticleSystem Explosion; private void FixedUpdate() { if (Health <= 50) { Smoke.Play(); } if (SceneManager.GetActiveScene().name == "Car Select") { return; } } void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Target")) { Won = true; } if (other.gameObject.CompareTag("Barrier")) { Health -= 3; } else if (other.gameObject.CompareTag("Rock")) { Health -= 7; } else if (other.gameObject.CompareTag("Crate")) { Health -= 1; } else if (other.gameObject.CompareTag("Cone")) { Health -= 4; } else if (other.gameObject.CompareTag("Spool")) { Health -= 3; } else if (other.gameObject.CompareTag("Barrel")) { Health -= 2; } else if(other.gameObject.CompareTag("Mega Rock")) { Health -= 50; } else if (other.gameObject.CompareTag("DeadLine")) { gameover = true; Instantiate(Explosion, transform.position, Quaternion.identity); Explosion.Play(); Destroy(gameObject); } else if (other.gameObject.CompareTag("Enemy")) { gameover = true; Instantiate(Explosion, transform.position, Quaternion.identity); } } // Update is called once per frame void Update() { NoSpeed(); if (Health <= 0) { gameover = true; speed = 0; turnSpeed = 0; Health = 0; } if (Health <= 49) { speed = 10.0f; } if (Won == false || gameover == false) { Explosion.Stop(); horizontalInput = Input.GetAxis("Horizontal"); //Moves the car forwards transform.Translate(Vector3.forward * Time.deltaTime * speed); //Rotate the car so it can turn Right or Left to Horizontal Axis transform.Rotate(Vector3.up, Time.deltaTime * turnSpeed * horizontalInput); } if (Health <= 50) { Smoke.Play(); } if (Health <= 50 || Won == true || gameover == true) { Dust.Stop(); Dust2.Stop(); } if(Won == true) { Won = true; speed = 0; turnSpeed = 0; } } void NoSpeed() { if(SceneManager.GetActiveScene().name == "Car Select") { speed = 0f; turnSpeed = 0f; } } }
内容的提问来源于stack exchange,提问作者DabTop Grid
相关产品推荐
相关产品推荐

