This is the code i am using to make a survival game. It is partly done, but i am trying to make it so that if an enemy enters a certain trigger and the mouse button is pressed it is removed/defeated, but it doesn’t work. Can anyone help me fix it?
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.SceneManagement;
public class Survival : MonoBehaviour {
public Text KeyText;
public AudioSource Gun;
public AudioSource NoAmmo;
public AudioSource AnyAudio;
public string Next;
public string death;
private Rigidbody rb;
private int count;
private int wind;
public Text LifeText;
private int life;
public AudioSource Pickup;
void Start ()
{
rb = GetComponent<Rigidbody>();
count = 6;
SetCountText ();
life = 6;
SetLifeText ();
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("AudioPlay")) {
AnyAudio.Play ();
other.gameObject.SetActive (false);
}
if (other.gameObject.CompareTag ("Load")) {
SceneManager.LoadScene (Next);
}
if (other.gameObject.CompareTag ("Ammo")) {
other.gameObject.SetActive (false);
count = count + 2;
Pickup.Play ();
SetCountText ();
}
if (other.gameObject.CompareTag ("Hurt")) { ## I know this is here twice, but these are the places i have used this code
if (Input.GetMouseButtonDown (0) && count > 0) {
other.gameObject.SetActive (false);
life = life + 1;
SetLifeText ();
}
life = life - 1;
SetLifeText ();
}
}
void Update(Collider other){
if (Input.GetMouseButtonDown (0)) {
if (other.gameObject.CompareTag ("Hurt")) {
if (count <= 0) {
NoAmmo.Play ();
}
if (count > 0) {
Gun.Play ();
count = count - 1;
other.gameObject.SetActive (false);
SetCountText ();
}
}
if (count <= 0) {
NoAmmo.Play ();
}
if (count > 0) {
Gun.Play ();
count = count - 1;
SetCountText ();
}
}
}
void SetCountText ()
{
KeyText.text = count.ToString() + "/6" ;
}
void SetLifeText(){
if (life == 6) {
LifeText.text = "//////";
}
if (life == 5) {
LifeText.text = "/////";
}
if (life == 4) {
LifeText.text = "////";
}
if (life == 3) {
LifeText.text = "///";
}
if (life == 2) {
LifeText.text = "//";
}
if (life == 1) {
LifeText.text = "/";
}
if (life == 0) {
LifeText.text = "0";
SceneManager.LoadScene (death);
}
}
}