Advertisement
Pro_Unit

ClearMissingReferenceExample

Dec 27th, 2018
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3.  
  4. using UnityEngine;
  5.  
  6. public class ClearMissingReferenceExample : MonoBehaviour
  7. {
  8.     public List<GameObject> gameObjects;
  9.  
  10.     [ContextMenu ("Create GOs")]
  11.     void CreateGOs ()
  12.     {
  13.         for (int i = 0; i < 5; i++)
  14.         {
  15.             GameObject go = new GameObject ();
  16.             go.name = "GameObject" + go.GetInstanceID ();
  17.             go.transform.SetParent (transform);
  18.             gameObjects.Add (go);
  19.         }
  20.     }
  21.  
  22.     [ContextMenu ("Clear MissingReference")]
  23.     void ClearMissingReference ()
  24.     {
  25.         gameObjects.RemoveAll (item => item == null);
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement