public static InstanceDestroyer Create(GameObject where, float ml = 5f)
    {
        Debug.Log("adding destroyer to " + where.name);
        InstanceDestroyer InsDes = where.AddComponent <InstanceDestroyer>();

        InsDes.maxLifetime = ml;
        return(InsDes);
    }
        /// <summary>Instantiates an inactive <see cref="BombComponent"/> of the specified type using the <see cref="BombGenerator"/> prefab.</summary>
        /// <remarks>
        /// Unless it is activated or its parent is changed to an active GameObject, the instance will not receive an Awake or Start call.
        ///	Unless its parent is changed, the instance will be automatically destroyed with this GameObject.
        ///	</remarks>
        // We avoid Awaking the new instance because that would interfere with module numbers and possibly cause other unwanted side effects.
        protected TempComponentWrapper <T> InstantiateComponent <T>() where T : BombComponent
        {
            var modulePrefab = GetComponentPrefab <T>();
            var tempParent   = new GameObject(modulePrefab.name + " Temp Parent").transform;

            InstanceDestroyer.AddObjectToDestroy(this.gameObject, tempParent);
            tempParent.gameObject.SetActive(false);
            return(new TempComponentWrapper <T>(tempParent, Instantiate(modulePrefab, tempParent, false)));
        }
예제 #3
0
 void Start()
 {
     InstanceDestroyer.Create(gameObject, maxLifetime);
 }