IEnumerator FadeOut() { GetComponent <Collider>().enabled = false; var renderer = transform.Find("enemy/Cube_001").GetComponent <Renderer>(); renderer.material = fadeMaterial; renderer.shadowCastingMode = ShadowCastingMode.Off; var color = renderer.material.color; const float fadeOutDuration = 2; float timer = fadeOutDuration; while (timer > 0) { timer -= Time.deltaTime; color.a = timer / fadeOutDuration; var fraction = Time.deltaTime / fadeOutDuration; Pints.AddPints(numberOfPints * fraction); renderer.material.color = color; yield return(0); } Destroy(gameObject); }
IEnumerator AttackPlayer() { Debug.Log(gameObject + " decides to attack"); int targetX = -1, targetY = -1; IEnumerator path = null; while (aware) { if (path == null || targetX != Mathf.Round(player.transform.position.x) || targetY != Mathf.Round(player.transform.position.y)) { Interrupt(path); targetX = (int)Mathf.Round(player.transform.position.x); targetY = (int)Mathf.Round(player.transform.position.y); path = WalkPathToPoint(player.transform.position); } if (Vector3.Distance(transform.position, player.transform.position) < 0.75) { Debug.Log(Vector3.Distance(transform.position, player.transform.position)); Pints.AddPints(-2f * Time.deltaTime); } yield return(path.MoveNext()); } interrupt = true; }