I currently have a turret in game which fires small boxes at the player when the player is within a certain range of the turret. However I am stuck for what to do next script-wise. I need the bullet to kill the player on contact and load the level again. The script I have for my turret is as follows:
private var target : Transform;
function OnTriggerEnter(otherCollider : Collider) {
if (otherCollider.CompareTag("Player"))
{
target = otherCollider.transform;
Fire();
}
}
function OnTriggerExit(otherCollider : Collider) {
if (otherCollider.CompareTag("Player"))
{
target = null;
StopCoroutine("Fire"); // aborts the currently running Fire() coroutine
}
}
function Fire()
{
while (target != null)
{
var nextFire = Time.time + 2;
while (Time.time < nextFire)
{
transform.LookAt(target);
yield WaitForEndOfFrame();
}
// fire!
var bullet = Instantiate(bulletPrefab, transform.position, transform.rotation);
bullet.velocity = transform.forward * bulletSpeed;
}
}
What would I need to add to this code or the box in order to make the level re-load from the beginning? I’m aware of the application.LoadLevel(1) code, but I’m not sure how I would go about triggering this code when the box or bullet hits the player. For reference I am using a default third person controller.
Thanks in advance