Question by 
               pinkyking256 · Jul 08, 2020 at 05:03 PM · 
                2dprefabs  
              
 
              Prefab Powerup works, but instantiated clone does not
This is the code that I have on my player script:
  void OnTriggerEnter2D (Collider2D collider2D)
     {
         if (collider2D.gameObject.tag == "powerup")
         {
             PoweredUp = true;
             PowerupTimer = PowerupTimer;
             PowerupTimer -= Time.deltaTime;
         }
     }
 
               ...and this is on the powerup itself:
     void OnTriggerEnter2D(Collider2D collider2D)
     {
         if (collider2D.gameObject.tag == "Player")
         {
             Destroy(gameObject);
         }
     }
 
               For some reason, any prefabs that I drop directly into my scene work perfectly, however instantiated ones get destroyed, but for some reason, do not trigger the "PoweredUp" boolean.
Here is a more complicated script that I have on the spawner objects:
  public GameObject powerup;
     public float minWait;
     public float maxWait;
 
     private bool isSpawning;
 
     IEnumerator SpawnObject(float seconds)
     {
         Debug.Log("Waiting for " + seconds + " seconds");
 
         yield return new WaitForSeconds(seconds);
         Instantiate(powerup, transform.position, transform.rotation);    
         isSpawning = false;
     }
 
     void Update()
     {
         if (!isSpawning)
         {
             isSpawning = true;
             StartCoroutine(SpawnObject(UnityEngine.Random.Range(minWait, maxWait)));
         }
 
               Any solutions, or ways I could have done this more efficiently?
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by pinkyking256 · Jul 08, 2020 at 05:31 PM
Ok I got it, there was a compiler warning referencing the line "PowerupTimer = PowerupTimer" so I just changed it to "PowerupTimer = 7f" which is pretty much the same thing.
Your answer