Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to destroy duplicate gameObject, except this, in a scene?

Discussion in 'Visual Scripting' started by kverma1985, Aug 31, 2021.

  1. kverma1985

    kverma1985

    Joined:
    Aug 31, 2021
    Posts:
    2
    Hello,

    I'm using Visual Scripting for the first time and I'm attempting to create a simple game without any written code, i.e. entirely through Visual Scripting using Script Machine. Right now I'm stuck at a fairly simple code where I'm not sure how to instantiate a class and destroy all rogue gameObjects by using Script Machine only.

    Here's the code:
    Code (CSharp):
    1. public static Player myInstance;
    2.  
    3. void start () {
    4.  
    5.     if (myInstance == NULL) {
    6.         myInstance = this;
    7.     }
    8.     else {
    9.         Destroy(gameObject);
    10.     }
    11.    
    12.     DontDestroyOnLoad(gameObject);
    13. }
    What I have managed to get by far is this attached snapshot...


    Any one knows how I should proceed further?
     

    Attached Files:

    • Snip.PNG
      Snip.PNG
      File size:
      24.4 KB
      Views:
      267
  2. Songh0318

    Songh0318

    Joined:
    Nov 29, 2016
    Posts:
    6
    I haven't tried it but maybe somewhere along the line of this:
    This is why I don't want to do every logic with visual scripting.
    upload_2021-9-6_0-5-37.png