void OnCollisionStay2D(Collision2D collision) { // Collided with a plant!? Game over, buddy if (collision.gameObject.tag == "Plant") { gameOverWall = GameObject.Find ("EndOfGameWall"); gameOverWallScript = gameOverWall.GetComponent<GameOverWall>(); gameOverWallScript.LostGame(); } // Collided with a prey? Eat it, yo if (collision.gameObject.tag == "Herbivore") { // Eat once a second isHunger = false; //GetComponent<Animator>().SetTrigger("isHunger"); if (Time.time - last >= 1) { currentHP = collision.gameObject.GetComponent<Health>(); currentHP.lowerHealth(amountToEatPerTick); if(currentHP.eaten == true){ isHunger = true; transform.position += new Vector3(4,0,0); } hunger += amountToEatPerTick; //Debug.Log("hunger is " + hunger); last = Time.time; if (hunger >= fullHungerValue) { BuildMenu.score += fullHungerValue; Destroy(gameObject); } } } }
void OnCollisionStay2D(Collision2D collision) { // Collided with a plant!? Game over, buddy if (collision.gameObject.tag == "Plant") { gameOverWall = GameObject.Find("EndOfGameWall"); gameOverWallScript = gameOverWall.GetComponent <GameOverWall>(); gameOverWallScript.LostGame(); } // Collided with a prey? Eat it, yo if (collision.gameObject.tag == "Herbivore") { // Eat once a second isHunger = false; //GetComponent<Animator>().SetTrigger("isHunger"); if (Time.time - last >= 1) { currentHP = collision.gameObject.GetComponent <Health>(); currentHP.lowerHealth(amountToEatPerTick); if (currentHP.eaten == true) { isHunger = true; transform.position += new Vector3(4, 0, 0); } hunger += amountToEatPerTick; //Debug.Log("hunger is " + hunger); last = Time.time; if (hunger >= fullHungerValue) { BuildMenu.score += fullHungerValue; Destroy(gameObject); } } } }