Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Enemy wont deal damage

$
0
0
The player deals damage perfectly to an eanmy but the eanmy dont deal damage just says NullReferenceExeption: objact referance not set to an instance of an objact enemy script`using UnityEngine; using System.Collections; public class MobAI : MonoBehaviour { public Transform Player; public int Speed; public int LongRange; public int range; public int damage; public AnimationClip run; public AnimationClip idle; public AnimationClip attack; public int health; public AnimationClip death; public GameObject Self; public GameObject Target; void Start () { Target = GameObject.FindWithTag ("Player"); } void Update () { if (!isDead ()) { if (!animation.IsPlaying (attack.name)) { transform.LookAt (Player); if (Vector3.Distance (transform.position, Player.position) > range) { transform.position += transform.forward * Speed * Time.deltaTime; animation.Play (run.name); } else { animation.Play (attack.name); Target.GetComponent().getHit(damage); } } } else { Death (); } } public void getHit (int damage) { health = health - damage; } bool isDead () { if (health <= 0) { return true; } else { return false; } } void Death () { animation.Play(death.name); if(animation[death.name].time>animation[death.name].length*0.9) { Destroy(Self); } } } **health code:** using UnityEngine; using System.Collections; public class PlayerHealth : MonoBehaviour { public AnimationClip death; public float health; public float maxHealth; public float healthBarLength; public GameObject Self; void start () { healthBarLength = Screen.width / 4; } void update () { healthBarLength = (Screen.width / 4)*(health / (float)maxHealth); if (health > 0) { ClickToMove.Death = false; Damage.Death = false; } else { ClickToMove.Death = true; Damage.Death = true; animation.Play(death.name); if(animation[death.name].time>animation[death.name].length*0.9) { Destroy(Self); } } } void OnGUI() { GUI.backgroundColor = Color.red; GUI.Button(new Rect(10, 10, Screen.width / 4 / (maxHealth / health), 20), health + "/" + maxHealth); } public void getHit (int damage) { health = health - damage; } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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