public Bullet(Game game, Vector2 position, BulletSource bulletSource) : base(game) { this.position = position; this.bulletSource = bulletSource; bulletTex = BulletsManager.BulletTex[(int)bulletSource]; srcRect = new Rectangle(0, 0, 20, 20); destRect = new Rectangle((int)position.X, (int)position.Y, 20, 20); }
private void Awake() { fightStatus = GetComponent <FightStatus>(); if (tag == "Player") { sourceType = BulletSource.player; } else { sourceType = BulletSource.enemy; } lastBackgunHitEffect = new float[backgunHitEffects.Length]; bulletLayerMask = ~LayerMask.GetMask(new string[] { "Bullet" }); }
private IEnumerator damageArea(Vector3 center, float rad, int dmg, float interval, BulletSource source) { while (true) { // get all the colliders in range ArrayList damagedObjIDs = new ArrayList(); Collider[] hitColliders = Physics.OverlapSphere(center, rad); foreach (Collider collider in hitColliders) { // check null if (collider == null) { continue; } // check this game obj has been damaged or not int objID = collider.gameObject.GetInstanceID(); if (damagedObjIDs.Contains(objID)) { continue; } else { damagedObjIDs.Add(objID); } // ignore boundary and other bullets if (collider.tag == "Boundary" || collider.tag == "Bullet" || collider.tag == "Powerup") { // do nothing continue; } // ignore player (bullets from player) else if (collider.tag == "Player" && bulletSource == BulletSource.player) { // do nothing continue; } // ignore enemies (bullets from enemies) else if (collider.tag == "Enemy" && bulletSource == BulletSource.enemy) { // do nothing continue; } // hit anything else Damageable else { // apply damage to it Damageable target = collider.GetComponent <Damageable>(); if (target != null) { target.applyDamage(dmg); } } } // damage interval if (interval <= 0) { break; } else { yield return(new WaitForSeconds(interval)); } } }