• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by TheIncognito · Feb 08, 2014 at 10:01 PM · script loadinganother script

Script Deleting itself on run,

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> ();
                         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> ();
         tko.KillTroll ();
     }
 }

TKO Vanishes from the Hierarchy When I Press play.

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image getyour411 · Feb 08, 2014 at 10:03 PM 0
Share

Use PlayerPrefs SetInt() ?

avatar image TheIncognito · Feb 08, 2014 at 10:08 PM 0
Share

The script is there, but it dissapears when I click play, And I'd rather not replace my work with PlayerPrefs ($$anonymous$$ostly because they're mind boggling.)

avatar image Josh707 · Feb 08, 2014 at 10:15 PM 0
Share

By disappear do you mean removed or disabled? Before you post the script, are you using Destroy() at all? Perhaps you are calling Destroy(this) which removes the script component from the game object? If not, it would help to see the script :P

avatar image TheIncognito · Feb 08, 2014 at 10:18 PM 0
Share

Removed, But I'll go edit my OP and add the two scripts that make the $$anonymous$$ill Output work (Supposedly)

avatar image Lunaria · Feb 08, 2014 at 10:54 PM 0
Share

Did you put this code on your own character? I think this code should put on your monsters.

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to use Configurable Joints and DragRigidBody Script with a door 0 Answers

Changing a variable in another script for one object. 2 Answers

How to change texture of another object by clicking on a object? 0 Answers

detecting whether the object has been clicked in another script 2 Answers

Loading font runtime from file 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges