Quantcast
Channel: Questions in topic: "die"
Viewing all articles
Browse latest Browse all 115

Kill the Player?

$
0
0
I made this script, but I cant seem to figure out how to make him die. I would like the scene to reset when his health hits 0. Here is the script: using UnityEngine; using System.Collections; public class EnemyAttack : MonoBehaviour { public GameObject target; public float attackTimer; public float coolDown; // Use this for initialization void Start () { attackTimer = 0; coolDown = 2.0f; } // Update is called once per frame void Update () { if(attackTimer > 0) attackTimer -= Time.deltaTime; if(attackTimer < 0) attackTimer = 0; if(attackTimer == 0){ Attack(); attackTimer = coolDown; } } private void Attack(){ float distance = Vector3.Distance(target.transform.position, transform.position); Vector3 dir = (target.transform.position - transform.position).normalized; float direction = Vector3.Dot(dir, transform.forward); if(distance < 2.5f) { if(direction > 0) { PlayerHealth eh = (PlayerHealth)target.GetComponent("PlayerHealth"); eh.AddjustCurrentHealth(-10); } } } }

Viewing all articles
Browse latest Browse all 115

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>