- Home /
Question by
SolidSlish · Nov 14, 2019 at 08:54 PM ·
tagenablespherecollider
Enable Sphere Collider with Tag rather than Variable
So I have a magnet power up that works when the sphere collider is enabled. How do I make it so that I can apply it to all my coins rather that one? Here is my script so far.
Also, I'm trying to add a timer effect using IEnumerator, but its not working. Any help?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PowerUp : MonoBehaviour {
public GameObject Coin;
public GameObject Powerup;
public string searchTag;
public float duration = 4f;
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
StartCoroutine( Pickup(other) );
}
}
IEnumerator Pickup(Collider Attractor)
{
Coin.GetComponent<SphereCollider>().enabled = true;
Powerup.GetComponent<MeshRenderer>().enabled = false;
yield return new WaitForSeconds(duration);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612214822im_/https://answers.unity.com/themes/thub/images/avi.jpg)