Hi there, I'm finishing up the Zombie Gallery. I'm nearly finished except for the part where once we reach the helicopter, I would either win or lose based on the zombies I have left. I used a gameobject "titled EndGame" with a box collider on Trigger along with a proper counter for how many zombies are left with each hit. However, I don't get the proper console alert for the end of my game once I reach EndGame. Here is my Code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class RCastPistolScript : MonoBehaviour
{
public GameObject bulletHole;
public int ammoLimt;
public Text ammo;
public int zombiecount;
public Text count;
public GameObject endGame;
void Update()
{
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit))
{
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
}
if(Input.GetButtonDown("Fire1"))
{
Instantiate(bulletHole, hit.point, Quaternion.LookRotation(hit.normal));
if(hit.collider.gameObject.tag == "Zombie")
{
iTween.RotateTo(hit.collider.gameObject.transform. parent.gameObject, iTween.Hash(
"x", 90f,
"time", .5f,
"easetype", "spring"
));
zombiecount = zombiecount - 1;
count.text = zombiecount.ToString();
}
if(hit.collider.gameObject.tag == "Child")
{
print("Oh no! A kid!");
}
ammoLimt = ammoLimt - 1;
ammo.text = ammoLimt.ToString();
}
}
private void OnTriggerEnter(Collider other)
{
if (endGame)
{
if (zombiecount <= 0)
{
print("You win!");
}
}
if (zombiecount > 0)
{
print("You forgot one!");
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class RCastPistolScript : MonoBehaviour
{
public GameObject bulletHole;
public int ammoLimt;
public Text ammo;
public int zombiecount;
public Text count;
public GameObject endGame;
void Update()
{
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit))
{
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
}
if(Input.GetButtonDown("Fire1"))
{
Instantiate(bulletHole, hit.point, Quaternion.LookRotation(hit.normal));
if(hit.collider.gameObject.tag == "Zombie")
{
iTween.RotateTo(hit.collider.gameObject.transform. parent.gameObject, iTween.Hash(
"x", 90f,
"time", .5f,
"easetype", "spring"
));
zombiecount = zombiecount - 1;
count.text = zombiecount.ToString();
}
if(hit.collider.gameObject.tag == "Child")
{
print("Oh no! A kid!");
}
ammoLimt = ammoLimt - 1;
ammo.text = ammoLimt.ToString();
}
}
private void OnTriggerEnter(Collider other)
{
if (endGame)
{
if (zombiecount <= 0)
{
print("You win!");
}
}
if (zombiecount > 0)
{
print("You forgot one!");
}
}
}
Comment