This question was
closed Feb 03, 2017 at 03:08 PM by
hexagonius.
Question by
mike1233 · Feb 03, 2017 at 02:32 PM ·
2d gameif-statementselsedieoncollision
code so if 1 enemy isnt killed every 4 seconds player dies?
how do I code it so if 1 enemy isn't killed at least every 4 seconds the player dies?
not sure if this is right code to put here but this script is on all the enemies enemies are instantiated every second at least this is the enemys die script
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(AudioSource))]
public class dedd : MonoBehaviour {
public AudioClip pop1;
public AudioClip boing;
AudioSource audio;
Animator anim; //reference to the animator component
void Start()
{
audio = GetComponent<AudioSource>();
//get reference to the animator component
anim = GetComponent<Animator> ();
}
void OnCollisionEnter2D(Collision2D other)
//void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Player" || other.gameObject.tag == "Wall" )
{
// do something when we collide with "enemy1" OR "enemy2"
anim.Play("fishded");
anim.SetTrigger("Die");
GetComponent<AudioSource> ().Play ();
audio.PlayOneShot(pop1, 0.7F);
}
else if (other.gameObject.tag == "bad" || other.gameObject.tag == "bad" )
{
// do something else when we collide with "enemy3" OR "enemy4"
anim.Play("fishded");
anim.SetTrigger("Die");
GetComponent<AudioSource> ().Play ();
audio.PlayOneShot(boing, 0.7F);
}
}
}
Comment