void Start() { gorbonRB = GetComponent <Rigidbody>(); overlord = GameObject.Find("GameManager").gameObject.GetComponent <GorbonOverlord>(); if (overlord != null) { overlord.AddGorbon(this); } SetShieldLights(onMaterial); currentHealth = maxHealth; jumpForce = 10f; }
IEnumerator Attack() { Jump(); yield return(new WaitForSeconds(1f)); Vector3 explosionPos = transform.position; gorbonRB.isKinematic = true; gorbonRB.velocity = Vector3.zero; transform.position = explosionPos; Collider[] colliders = Physics.OverlapSphere(explosionPos, attackRadius); foreach (Collider hit in colliders) { Rigidbody rb = hit.GetComponent <Rigidbody>(); if (rb != null) { rb.AddExplosionForce(attackForce, explosionPos, attackRadius); RaycastHit attackHit; if (rb.CompareTag("Player") && Physics.Linecast(transform.position, target.position, out attackHit, visibilityMask)) { if (attackHit.transform.CompareTag("Player")) { float realDamage = attackDamage - 3f * (target.position - transform.position).magnitude; realDamage = Mathf.Clamp(realDamage, 0f, attackDamage); rb.GetComponent <PlayerControl>().DamagePlayer(realDamage); Debug.LogWarning(attackDamage + " | " + (3f * (target.position - transform.position).magnitude) + " | " + realDamage); } } if (rb.CompareTag("PlayerShip")) { rb.GetComponent <ShipCollision>().BreakShip(); if (target == rb.transform) { FindObjectOfType <ShipController>().Exit(); } } } } MeshRenderer[] meshes = GetComponentsInChildren <MeshRenderer>(); foreach (MeshRenderer mesh in meshes) { mesh.enabled = false; } explosion.Play(); yield return(new WaitForSeconds(1f)); if (overlord != null) { overlord.RemoveGorbon(this); overlord = null; } Destroy(gameObject); }