void NoiseBubble(Vector3 pos) { Collider[] colliders = Physics.OverlapSphere(pos, weaponStats.noiseRadius); foreach (Collider hit in colliders) { ai = hit.GetComponent <EnemyAI>(); if (ai != null) { ai.alerted = true; ai.StartPatrol(); } } }
void AddExplosion(Vector3 position) { Instantiate(explosion, position, Quaternion.identity); Collider[] colliders = Physics.OverlapSphere(position, radius); foreach (Collider hit in colliders) { unparent unp = hit.gameObject.GetComponent <unparent>(); if (unp != null) { unp.unparentMesh(); Destroy(hit.GetComponent <unparent>()); Destroy(hit.GetComponent <BoxCollider>()); } if (hit && hit.GetComponent <Rigidbody>()) { hit.GetComponent <Rigidbody>().AddExplosionForce(force, position, radius, 3.0F); } } }
void Explosion(Vector3 center, float radius) { Collider[] hitColliders = Physics.OverlapSphere(center, radius, layerMask); foreach (Collider hit in hitColliders) { Rigidbody rb = hit.GetComponent <Rigidbody>(); if (rb != null) { rb.AddExplosionForce(20, center, radius, 2, ForceMode.Impulse); } } }
void Update() { ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, Mathf.Infinity) && Input.GetMouseButtonDown(0)) { if (hit.GetComponent <Collider>() == this.GetComponent <Collider>()) { showLabel = true; } else { showLabel = false; } } }
private void Update() { if (Physics.Raycast(transform.position, transform.forward, out hit, range) && hit.collider.tag == "Interactable") { hit.collider.gameObject.GetComponent <Outline>().OutlineMode = Outline.Mode.OutlineAll; hits.Add(hit.collider.gameObject); } else { foreach (GameObject hit in hits) { hit.GetComponent <Outline>().OutlineMode = Outline.Mode.OutlineHidden; } hits.Clear(); } Debug.DrawRay(transform.position, transform.forward, Color.red, 500f); }