Created
June 12, 2019 12:06
-
-
Save iamgabrielma/f2be104910cd42ab372028e540d03867 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## in PlayerCollisions.cs , attached to the player game object: | |
public bool isPlayerTakingDamage; | |
public void Start(){ | |
isPlayerTakingDamage = false; | |
} | |
void OnTriggerEnter2D(Collider2D collision){ | |
if (collision.tag == "Enemy"){ | |
isPlayerTakingDamage = true; | |
} | |
} | |
## GameManager.cs | |
private void Update(){ | |
if (playerObject != null) | |
{ | |
if (isGameOver == false && playerCollisionsScript.GetComponent<PlayerCollisions>().isPlayerTakingDamage == true) | |
{ | |
StartCoroutine(playerReceivesDamageTimer()); | |
} | |
} | |
} | |
private IEnumerator playerReceivesDamageTimer() | |
{ | |
playerCollisionsScript.GetComponent<PlayerCollisions>().isPlayerTakingDamage = false; | |
score--; | |
FloatingTextController.CreateFloatingText("Score --!", forestFloatingTextColor); | |
yield return new WaitForSeconds(playerReceivesDamageTimeout); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment