Hello
I'm working on a 2d platformer and I'm trying to give my player invulnerability for 3 seconds after getting hit. but I just cant seem to get it to work. any ideas how to fix this script?
public class Invulnerability : MonoBehaviour
{
Renderer rend;
Color c;
void start ()
{
rend = GetComponent();
c = rend.material.color;
}
void OnTriggerEnter2D(Collider2D col)
{
if (col.gameObject.tag == ("Enemy") && GameControlScript.health > 0)
StartCoroutine ("GetInvulnerable");
}
IEnumerator GetInvulnerable()
{
Physics2D.IgnoreLayerCollision (8, 10, true);
c.a = 0.5f;
rend.material.color = c;
yield return new WaitForSeconds (3f);
Physics2D.IgnoreLayerCollision (8, 10, false);
c.a = 1f;
rend.material.color = c;
}
}
↧