Hey Guys,
I’m trying to make Block Breaker game. Now, I’m trying to create random power ups as a chance %5 when a block is destroyed.
This is where I instantiate a game object randomly.
public class BlockSquare : MonoBehaviour
{
[SerializeField] GameObject specPow;
public GameObject spcPow;
public void SpecPowInstantiate()
{
int randomNum = UnityEngine.Random.Range(0,20 );
if(randomNum == 10)
{
spcPow = Instantiate(specPow, transform.position, transform.rotation) as GameObject;
Destroy(spcPow, 5f);
}
}
}
This is where I tried to destroy clone gameobjects. But I couldnt :
public class Paddle : MonoBehaviour
{
BlockSquare blckSpecPow;
private void OnTriggerEnter2D(Collider2D collision)
{
if(gameObject.tag == "SpecPowGameObject")
{
Destroy(blckSpecPow.spcPow);
}
}
}