Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

Script Deleting itself on run,

$
0
0
I have a Small MMO project (not to be published, might if I pretty it up) and it has an issue. My Quest are basic. Kill a random amount of Trolls, and when you reach that amount, you go back to the over world. but my script that counts the kills is Deleting itself from my character when I run the game in Unity. how do I fix it? My KillEnemy Script using UnityEngine; using System.Collections; public class KillEnemy : MonoBehaviour { int EHealth = 100; int Damage = 25; void OnTriggerEnter(Collider col) { if (col.gameObject.tag == "Fireball") { EHealth -= Damage; } if (EHealth <= 0) { Destroy (gameObject); TKO tko; tko = GetComponent (); tko.KillTroll (); } } } And this is my KillOutput Script: using UnityEngine; using System.Collections; public class TKO : MonoBehaviour { public int TrollKilled = 0; public int MaxNeeded; void Start() { MaxNeeded = Random.Range (10, 51); } // Update is called once per frame public void KillTroll () { TrollKilled ++; } void OnGUI() { GUI.Box (new Rect (0, 0, Screen.width / 2, 20), TrollKilled + "/" + MaxNeeded); } void Update () { if (TrollKilled <= MaxNeeded) Application.LoadLevel (1); } } **EDIT** I've Updated The KillEnemy Script, using UnityEngine; using System.Collections; public class KillEnemy : MonoBehaviour { int EHealth = 100; int Damage = 25; private TKO tko; void OnTriggerEnter(Collider col) { if (col.gameObject.tag == "Fireball") { EHealth -= Damage; } if(EHealth <= 0) Destroy (gameObject); AddPoint (); } void AddPoint() { tko = GetComponent (); tko.KillTroll (); } } TKO Vanishes from the Hierarchy When I Press play.

Viewing all articles
Browse latest Browse all 171066

Trending Articles



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