- Home /
physics.OverlapSphere colliders
can someone please help me with physics.OverlapSphere. I am trying to make all gameObjects active gameObject.SetActive(true) in sphere with radius 30 and position of player.trasform.position.
I was trying with this incomplete code, but I dont know what to do.
#pragma strict
var player : GameObject;
var radius = 30;
var colliders : Collider[];
function OnCollisionEnter(collision : Collision) {
colliders = Physics.OverlapSphere (player.transform.position, radius);
for (var i = 0; i < colliders.Length; i++) {
}
}
Answer by BigRoy · Jan 02, 2014 at 09:20 PM
Based on your code something like this:
#pragma strict
var player : GameObject;
var radius = 30;
var colliders : Collider[];
function OnCollisionEnter(collision : Collision) {
colliders = Physics.OverlapSphere (player.transform.position, radius);
for (var i = 0; i < colliders.Length; i++) {
colliders[i].gameObject.SetActive(true);
}
}
Sidenote
You've placed it inside the OnCollisionEnter() method of the Player. This means it will get run everytime the gameObject that contains this script starts a collision with another object. Maybe you missed that?
I placed your script in Update function, and now it is working. thank you :)
Your answer
Follow this Question
Related Questions
Set Gameobject active using if statement and collider 1 Answer
Box collider doesn't work with player object 0 Answers
Adding lots of colliders in a single frame 0 Answers
Script is only working when slowing down timescale 0 Answers
What are best practices for getting your character to not fall through the floor? 1 Answer