- Home /
Question by
unity_SKWoexFmU7gaQw · Nov 24, 2019 at 11:50 PM ·
2d gamespace shooteraudiolisteneraudioplay
Activating audioclip explosion sound when bullet hits enemy in 2d spaceship game
Just needing some help on my code adding sound effects when the bullet hits the enemy fighter the audio clip plays a few tenths of a seconds after the explosion visual explosion. Below is just a screenshot and below is suppose to be two separate codes.
using UnityEngine;
using System.Collections;
public class DestroyStuff : MonoBehaviour {
private GameController gameController;
public GameObject explosion;
void Start() {
GameObject gameControllerObject = GameObject.FindWithTag ("gamecontroller");
if (gameControllerObject != null) {
gameController = gameControllerObject.GetComponent <GameController> ();
}
if (gameController == null) {
Debug.Log ("Cannot find 'GameController' script");
}
}
void OnTriggerEnter2D(Collider2D other) {
if (other.tag == "enemyfighter") {
Instantiate(explosion, other.transform.position, Quaternion.identity);
Destroy (other.gameObject);
Destroy(gameObject);
gameController.AddScore();
}
}
}
---------------------------------------------------------------------------------------------------------- using UnityEngine; using System.Collections;
public class MoveEnemyFighter : MonoBehaviour {
public Rigidbody2D enrb;
private int count;
// Use this for initialization
void Start() {
enrb=GetComponent<Rigidbody2D>();
enrb.velocity= new Vector2 (-3.0f, 0.0f);
}
// Update is called once per frame
void Update() {
if (transform.position.x < -12.0f) {
Destroy(gameObject);
}
}
}
fighterscreenshot.png
(428.1 kB)
Comment