unity3d - C# Unity Engine destroy() subclass -


hello have code:

public abstract class test : monobehaviour {     public abstract void onstart();     public abstract void onupdate();      private void start()     {         onstart();     }      private void update()     {         if (input.getkeydown(keycode.x))         {             destroy(this);         }         onupdate()     } } 

then have this:

public class secondtest : test {     public override void onstart()     {      }      public override void onupdate()     {         writter.log("running");     } } 

however whenever press x, writter keeps logging, seems instance of "test" gets destroyed not "secondtest" there way solve this? thank you!

*op explained intention cause children destroyed when parent is.

  1. the solution better handled @ '(test)manager' or 'levelmanager'.
  2. you assign children or prefabs (test)manager manually, or (test)manager instantiate child prefab.

    gameobject child = instantiate(prefab);  child.transform.setparent(gameobject.transform); //set child's parent manager 
  3. then in (test)manager

    private void update() {     if (input.getkeydown(keycode.x))     {         for(int i=0;i<gameobject.transform.childcount;i++)            destroy(gameobject.transform.getchild(i).gameobject);     } } 

this crude suggestion, there better ways such holding references children in manager versus parenting.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -