Skip to content

Instantly share code, notes, and snippets.

@iamgabrielma
Created June 12, 2019 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamgabrielma/f2be104910cd42ab372028e540d03867 to your computer and use it in GitHub Desktop.
Save iamgabrielma/f2be104910cd42ab372028e540d03867 to your computer and use it in GitHub Desktop.
## 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