void Update() { transform.position += dir * speed * Time.deltaTime; foreach (Collider other in Physics.OverlapSphere(transform.position, hitRadius)) { TopdownPlayer player = Utility.FindAncestor <TopdownPlayer>(other.gameObject); if (player != null) { continue; } Attackable target = Utility.FindAncestor <Attackable>(other.gameObject); if (target != null && game.IsEffectiveAgainst(word, target.GetWord())) { target.OnDamaged(); Utility.Instantiate(hitFx, transform.position); } else { AudioSource.PlayClipAtPoint(dudClip, transform.position); Utility.Instantiate(dudFx, transform.position); } Destroy(gameObject); } }
public void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag != "Enemy" && collision.gameObject.tag != "Bullet") { hitPlayer = collision.gameObject.GetComponent <TopdownPlayer>(); if (hitPlayer) { hitPlayer.TakeDamage(3); } Destroy(gameObject); } }
// Use this for initialization void Start() { mover = GetComponent <TopdownMover>(); Utility.Assert(mover != null); game = Utility.FindAncestor <TopdownGame>(gameObject); Utility.Assert(game != null); player = game.GetPlayer(); Utility.Assert(player != null); foreach (Attackable part in gameObject.GetComponentsInChildren <Attackable>()) { parts.Add(part); part.dieEvent.AddHandler(gameObject, OnPartDie); } }
// Use this for initialization void Start() { mover = GetComponent<TopdownMover>(); Utility.Assert( mover != null ); game = Utility.FindAncestor<TopdownGame>(gameObject); Utility.Assert( game != null ); player = game.GetPlayer(); Utility.Assert( player != null ); foreach( Attackable part in gameObject.GetComponentsInChildren<Attackable>() ) { parts.Add(part); part.dieEvent.AddHandler(gameObject, OnPartDie); } }
public void OnCollisionEnter2D(Collision2D collision) { player = collision.gameObject.GetComponent <TopdownPlayer>(); if (player) { if (DoorKeyType == Key.KeyType.RED && player.redKeys > 0) { player.redKeys--; AudioSource.PlayClipAtPoint(open, Camera.main.transform.position); Destroy(gameObject); } else if (DoorKeyType == Key.KeyType.BLUE && player.blueKeys > 0) { player.blueKeys--; AudioSource.PlayClipAtPoint(open, Camera.main.transform.position); Destroy(gameObject); } } }