void CheckForCommie() { if (Time.time > nextFire) { RaycastHit2D[] hit = Physics2D.RaycastAll(transform.position, RigidBody.velocity.normalized, CommieLookDistance, CollideLayers); bool seeCommie = false; foreach (RaycastHit2D item in hit) { if (item.collider.gameObject != this.gameObject) { Commie hitCommie = item.collider.GetComponent <Commie> (); if (hitCommie != null) { seeCommie = true; } } } bool randomFire = (Random.Range(0, 100) < RandomFireChance); if (seeCommie || randomFire) { FireProjectile(MyProjectile); nextFire = Time.time + FireRate; if (mySprite.isVisible) { MyController.SFXSource.PlayOneShot(MyWeaponSound); } } } }
public void BecomeCommie() { GameObject newCommieObject = (GameObject)Instantiate(CommiePrefab, transform.position, Quaternion.identity); Commie newCommie = newCommieObject.GetComponent <Commie> (); newCommie.transform.parent = MyController.CommieContainer; newCommie.MyDirection = this.MyDirection; newCommie.StartVelocity = this.RigidBody.velocity; newCommie.CivilianPrefab = this.MyPrefab; if (mySprite.isVisible) { MyController.SFXSource.PlayOneShot(MyController.CommieSound); } MyController.CivilianCount--; MyController.PlayerConversions++; Destroy(this.gameObject); }
void EnemyMegaphoneHit(Collider2D coll) { Commie hitCommie = coll.GetComponent <Commie> (); if (hitCommie != null) { hitCommie.Hit = true; hitCommie.BecomeCivilian(); MyController.Score -= 100; MyController.HitPoints -= 2; return; } PlayerController hitPlayer = coll.GetComponent <PlayerController> (); if (hitPlayer != null && !hitPlayer.Dead) { MyController.HitPoints -= 1; MyController.SFXSource.PlayOneShot(MyController.PlayerHitSound); return; } }