Another Physics.OverlapSphere question
When I check to see the hitColliders.Length it says that the size is 0. Why isn't my array filling up?
void Update () {
if (Input.GetMouseButtonDown(0)) {
if (iu.brush) {
Sweep();
}
}
}
void Sweep() {
Vector3 mousePosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, camDist);
Vector3 objPosition = Camera.main.ScreenToWorldPoint(mousePosition);
Collider[] hitColliders = Physics.OverlapSphere(objPosition, 5f);
Debug.Log(hitColliders.Length);
foreach (Collider col in hitColliders) {
if (col.gameObject.tag == "BrokenAcorn") {
col.GetComponent<Rigidbody2D>().AddForce(new Vector2(1000, 200));
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How to create chain with realistic physics 1 Answer
Question on Physics.Simulate Behavior 0 Answers
Wheel Colliders - Cannot Attach to Vehicle/Super huge??? 1 Answer
How to check if kinematic rigidbody is overlapping anything in the scene? 0 Answers
Why is my trigger collider acting like a normal collider? 1 Answer