Question by
mike1233 · Feb 09, 2017 at 10:25 PM ·
2d gameoncollisionenteroncollision
code if 2 or more enemies are killed at same time?
How to code a animation play if 2 or more enemies are killed at same time?
2d game
I don't know how to code this when 2 or more enemies are killed I want a sound and animation to play like a prize , so every time it happens this occurs.
heres one of the current script I have on the enemies
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(AudioSource))]
public class fishdedd : MonoBehaviour {
public AudioClip pop1;
public AudioClip boing;
AudioSource audio;
Animator anim; //reference to the animator component
void Start()
{
audio = GetComponent<AudioSource>();
anim = GetComponent<Animator> ();
}
void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.tag == "Player" || other.gameObject.tag == "Wall" )
{
anim.Play("fishded");
anim.SetTrigger("Die");
GetComponent<AudioSource> ().Play ();
audio.PlayOneShot(pop1, 0.7F);
DeathWatch.ReportDeath ();
//ScoreManager.score += scoreValue;
}
else if (other.gameObject.tag == "shark" || other.gameObject.tag == "shark" )
{
anim.Play("fishded");
anim.SetTrigger("Die");
GetComponent<AudioSource> ().Play ();
audio.PlayOneShot(boing, 0.7F);
DeathWatch.ReportDeath ();
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612110734im_/https://answers.unity.com/themes/thub/images/avi.jpg)