void AttackMeleeRange() { transform.LookAt(shipTransform); RaycastHit[] hit = Physics.BoxCastAll(this.transform.position, new Vector3(1, 1, 1), Vector3.Normalize(-transform.position + shipTransform.position), Quaternion.identity, maxAttackDistance); for (int i = 0; i < hit.Length && i < maxTargets; i++) { if (hit[i].collider.GetComponent <ShieldBehavior>()) { ShieldBehavior shield = hit[i].collider.GetComponent <ShieldBehavior>(); shield.TakeDamage(status[level - 1].meleeDamage); } else if (hit[i].collider.GetComponent <ShipController>()) { ShipController ship = hit[i].collider.GetComponent <ShipController>(); ship.TakeDamage(status[level - 1].meleeDamage); HealthPanel.OnHealthChange?.Invoke(ship.GetCurrentHealth()); } } currentMeleeAttackTime = 0; currentMelleAttackDelay = 0; inAttack = false; Shoot(attackView); }
void AttackMelle() { transform.LookAt(shipTransform); Ray ray = new Ray(this.gameObject.transform.position, Vector3.Normalize(-transform.position + shipTransform.position)); RaycastHit[] hit = Physics.RaycastAll(ray, maxAttackDistance); for (int i = 0; i < hit.Length && i < maxTargets; i++) { if (hit[i].collider.GetComponent <ShieldBehavior>()) { ShieldBehavior shield = hit[i].collider.GetComponent <ShieldBehavior>(); shield.TakeDamage(status[level - 1].meleeDamage); } else if (hit[i].collider.GetComponent <ShipController>()) { ShipController ship = hit[i].collider.GetComponent <ShipController>(); ship.TakeDamage(status[level - 1].meleeDamage); HealthPanel.OnHealthChange?.Invoke(ship.GetCurrentHealth()); } } currentMeleeAttackTime = 0; Shoot(attackView); }
void CheckAllTargets() { if (currentTargets < 1) { currentTargets++; Collider[] newTargets = Physics.OverlapSphere(this.transform.position, radiusToDamage); List <GameObject> targetsAvaliable = new List <GameObject>(); for (int i = 0; i < newTargets.Length; i++) { if (newTargets[i].GetComponent <ShieldBehavior>()) { ShieldBehavior shield = newTargets[i].GetComponent <ShieldBehavior>(); shield.TakeDamage(damage); } else if (newTargets[i].GetComponent <ShipController>()) { ShipController ship = newTargets[i].GetComponent <ShipController>(); ship.TakeDamage(damage); } } } Destroy(this.gameObject); }
void OnParticleCollision(GameObject other) { if (other.GetComponent <ShieldBehavior>()) { ShieldBehavior shield = other.GetComponent <ShieldBehavior>(); shield.TakeDamage(damage); } else if (other.GetComponent <ShipController>()) { ShipController ship = other.GetComponent <ShipController>(); ship.TakeDamage(damage); } }
void OnParticleCollision(GameObject other) { if (other.GetComponent <ShieldBehavior>()) { ShieldBehavior shield = other.GetComponent <ShieldBehavior>(); shield.TakeDamage(damage); } else if (other.GetComponent <ShipController>()) { ShipController ship = other.GetComponent <ShipController>(); ship.TakeDamage(damage); HealthPanel.OnHealthChange?.Invoke(ship.GetCurrentHealth()); } }