private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.tag == "Pellet") { ui.IncrementScore(1); if (collision.gameObject.name.Contains("Power")) { GhostHivemindMovement hivemind = FindObjectOfType <GhostHivemindMovement>(); if (hivemind) { hivemind.BecomeFrightened(); } else { foreach (GameObject g in GameObject.FindGameObjectsWithTag("ghost")) { g.GetComponent <UpdatedGhostMovement>().BecomeFrightened(); } } isInvincible = true; invincibleTimer += invDurationPerPellet; // power pellets stack } Destroy(collision.gameObject); } if (collision.gameObject.tag == "ghost") { GhostHivemindMovement hivemind = FindObjectOfType <GhostHivemindMovement>(); UpdatedGhostMovement singular = collision.gameObject.GetComponent <UpdatedGhostMovement>(); if (singular && singular.respawn) { return; } if (isInvincible) { // do invincible behavior ui.IncrementScore(ghostScore); ghostScore *= 2; if (hivemind) { string ghostName = collision.gameObject.name; if (ghostName.Contains("Blinky")) { hivemind.Eaten("blinky"); } else if (ghostName.Contains("Pinky")) { hivemind.Eaten("pinky"); } else if (ghostName.Contains("Inky")) { hivemind.Eaten("inky"); } else if (ghostName.Contains("Clyde")) { hivemind.Eaten("clyde"); } } else if (singular) { singular.Eaten(); } } else { mapGenerator mapGen = FindObjectOfType <mapGenerator>(); mapGen.DecLives(); GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeAll; dead = true; GetComponent <Animator>().SetBool("Dead", true); GetComponent <CircleCollider2D>().enabled = false; StartCoroutine(Respawn()); } } }
void Start() { path = FindObjectOfType <PathFinding>(); ui = FindObjectOfType <UIDisplay>(); hive = FindObjectOfType <GhostHivemindMovement>(); }