- Home /
different particle on enemy second hit
so, i have an enemy which can be hit 2 times. The first time i hit him, a prefab (Particle) will start. The second time, when he dies, i want prefab 2 to start. The thing is, i really cant figure out how to get it to work. Should i make a counter of some sort? but would not that count all the enemys which i hit?
here is my script:
using UnityEngine;
using System.Collections;
public class shootGun : MonoBehaviour {
public AudioClip aShoot;
public float timer;
public float shootDelay;
public GameObject bulletHole;
public GameObject bulletHit1;
public GameObject bulletHit2;
// Use this for initialization
void Start () {
timer = 0f;
}
// Update is called once per frame
void Update () {
if (timer < 0.1f){
if (Input.GetButtonDown("Fire1")){
Shoot();
audio.PlayOneShot(aShoot);
timer += 0.5f;
}
}
timer -= Time.deltaTime * 1f;
if (timer == 0 || timer < 0){
timer = 0f;
}
}
void Shoot () {
RaycastHit hit;
if (Physics.Raycast (transform.position, transform.forward, out hit)){
Quaternion rot = Quaternion.FromToRotation (Vector3.up, hit.point);
if (hit.transform.tag == "enemiesPre"){
hit.transform.SendMessage("ApplyDamage", 50, SendMessageOptions.DontRequireReceiver);
// First Hit: Instantiate (bulletHit1, hit.point, rot);
// if Enemy dies (2nd Hit): Instantiate (bulletHit2, hit.point, rot);
} else {
Instantiate (bulletHole, hit.point, rot);
}
}
}
}
Comment