Trigger to increase gravity for another sprite.
Hello. I'm currently working on a bossfight in my 2d platformer. I'm very new to coding and unity and i've run into a problem. I have a floating boss with rigidbody2D (with gravity set to 0), i've created a circle collider on the boss but dragged it to be placed on top of a spinning orb. I want it so when my player picks up the orb the boss gets 1(or something like that depending on dramatic effect) in gravity and falls down in a pit of lava where my killzone is.
I used a variation of this script earlier for a jump powerup for the player:
private float startgravitation;
private bool active = true;
IEnumerator OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Enemy") && active)
{
active = false;
startgravitation = other.GetComponent<Rigidbody2D>().gravityScale;
other.GetComponent<Rigidbody2D>().gravityScale += 1f;
yield return new WaitForSeconds(500f);
other.GetComponent<Rigidbody2D>().gravityScale = startgravitation;
Debug.Log("hejhopp");
active = true;
}
}
}
The problem is with the "if (other.CompareTag("Enemy") && active)". If the tag is Enemy it wont activate when the player enters the trigger. And if the Tag is player the gravity will only affect the player.
I'm pretty sure that the answer is quite simple, i've just been staring me blind and cant see a solution! Take care!
Your answer
