Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Temporary invulnerability in a platformer

$
0
0
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; } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>