- Home /
Question by
SolidSlish · Nov 14, 2019 at 06:10 PM ·
animationbooleanmagnetpower-up
How to Activate my Magnet Power for a short time on Collision?
So basically, the way I have it set right now is that when I collide into the power up object, a sphere collider that;s attached to a magnet script will activate. However, I wanna make this apply to all gameobjects with a tag instead of just one singular gameobject. I'm using two scripts. One is for the power up and one is for the magnet. How do I properly apply the boolean or do whatever it takes to fixx this?
public class PowerUp : MonoBehaviour {
public GameObject gameobject;
void OnTriggerStay(Collider other)
{
if (other.CompareTag("Player"))
{
Pickup(other);
}
}
void Pickup(Collider Attractor)
{
gameobject.GetComponent<SphereCollider>().enabled = true;
}
}
public class AttractorScript : MonoBehaviour {
public float AttractorSpeed;
public bool isEnabled = true;
void Start()
{
isEnabled = true;
}
private void OnTriggerStay(Collider other)
{
if (other.CompareTag("Player"))
isEnabled = true;
{
transform.position = Vector3.MoveTowards(transform.position,other.transform.position,AttractorSpeed);
}
}
Comment