Right now I have a major hiccup in my game. I have a code running so that a "Bullet" shoots from the whale and when it collides with something it stops.
This is exactly what I want, except when it stops, it still sits there for 3 seconds waiting for the particle system to finish. During those three seconds if another enemy collides with it, they also "die".
So I am not able to delete the bullet from the scene due to the particle system having to finish, and I need it to stop working when it collides. I've tried turning on and off the collider, but then it only worked sometimes.
Here's the code I'm using for the bullet:
using UnityEngine;
using System.Collections;
public class MoveTrail : MonoBehaviour {
public int moveSpeed = 230;
public float killSpeed = 3f;
void Start(){
renderer.enabled = false;
}
// Update is called once per frame
void Update () {
transform.Translate (Vector3.right * Time.deltaTime * moveSpeed);
Destroy (gameObject, killSpeed);
}
void OnTriggerEnter2D(Collider2D col){
if (col.gameObject.tag == "Enemy") {
particleSystem.emissionRate = 0;
moveSpeed = 0;
}
if (col.gameObject.tag == "Sub") {
particleSystem.emissionRate = 0;
moveSpeed = 0;
}
}
}
And for the Enemies:
void OnTriggerEnter2D(Collider2D col){
if (col.gameObject.tag == "Bullet") {
air = air - 10;
}
}
I have a photo here to show you the problem. The bullet is hitting the sub as demonstrated by the red line, and then the bullet sits where the blue circle is, and the sub is constantly moving down, shown by the black arrow, so the enemies swim into the bullet and take damage as they follow the sub.
![Bullet Problem][1]
[1]: /storage/temp/36026-unityproblem.jpg
I have no idea what I can do to fix this, so if you have any ideas, I'm all open. Thanks!
↧