Hello there, I have created game with default particle collision. I used Explosion Particle, i need to destroy objects with that explosion, so i created OnParticleCollision with using tag name. but i miss something, someone please explain what i missed.
public void OnParticleCollision(GameObject Bomb_Explosion)
{
if(Bomb_Explosion.name == "Player")
{
Destroy(GameObject.Find("Player"));
GameTimer.Game_Seconds = 59;
GameTimer.Game_Minutes = 4;
Application.LoadLevel ("Game_Play_1");
}
if(Bomb_Explosion.name == "AI_One")
{
Destroy(GameObject.Find("AI_One"));
}
}
I have added two Images, the first is destroying the crate object, i placed that bomb into border of the crate. If i place that bomb into center of the crate, its like 2nd Image.
I assume you assigned this script above to the ParticleSystem, the problem here is that OnParticleCollision is called on the object that got hit by the particle (remember to have collisions and Send Collision Message checked in the particle system).
So, in order to make it work you need to add a tag to the ParticleSystem explosion like “explosion” and add a script to each object that should react to particles like:
void OnParticleCollision (ParticleSystem explosion){
if (explosion.gameObject.tag == "explosion")
Destroy(gameObject);
}
Here it is, i found a way to fix this.
if(Input.touchCount > 0)
if(Bomb_Button.HitTest(Input.GetTouch(0).position))
{
if (Instance == true)
{
Bomb_Temp = Instantiate(Bomb, Bomb_Place.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;
Explosion_Position = Bomb_Temp.transform.position;
Explosion_Rotation = Bomb_Temp.transform.rotation;
Bomb_Click = true;
Instance = false;
}
}
if(Bomb_Click == true)
{
Bomb_Time += Time.deltaTime;
if(Bomb_Time >= 3f)
{
Destroy(Bomb_Temp);
Bomb_Time = 0;
Bomb_Click = false;
Bomb_Visible = true;
Expose_Instance = true;
}
}
if(Bomb_Visible == true)
{
if(Expose_Instance == true)
{
audio.PlayOneShot (Explosion_Sound);
Explosion_Temp = Instantiate (Explosion, Explosion_Position, Explosion_Rotation)as GameObject;
Expose_Instance = false;
}
Explosion_Time += Time.deltaTime;
if(Explosion_Time >= 2f)
{
Destroy(Explosion_Temp);
Explosion_Time = 0;
Bomb_Visible = false;
Instance = true;
}
}