OK,
So I have a script that on start creates a SphereCollider for a trigger and uses a variable to set it’s radius. What I’m wanting to do is while in the editor I want to be able to see the Collider as well, or atleast a semi transparent sphere to simulate the collider.
Is there a way I can do this from the script?
Colliders already draw a wireframe gizmo that is green. Is that insufficient somehow?
I know that, but I create the collider from the script like so:
public class UnitTargetAndFiring: MonoBehaviour {
.....
// Use this for initialization
void Start () {
SphereCollider sc = (SphereCollider)gameObject.AddComponent("SphereCollider");
sc.radius = targetDistance;
sc.isTrigger = true;
}
.....
}
This does not display the collider in the editor, which is what I’m wanting. but since the the gameObjects that are using this have a variety of ranges and other colliders and triggers. So I felt this method was easiest.
Umm… But it does create a collider in the editor. You’ll see it if (a) you look in the scene view with that game object selected or (b) enable gizmos in the Game view.
Yes I can see in the game mode, but not when in the scene view. Even when I select object.
Though if I have the game running and switch back to the scene view I can see the collider, but not when the game is not running.
I was hoping for some method to to have it always show.
Well, if you are always going to have a script create it unconditionally, just add it to the game object (and not do it in script) that is in the scene.
But let’s assume you have some evil genius plan that I’m unaware of, implement the OnDrawGizmos() method in your script and draw it in there.
[ExecuteInEditMode]
Just put that at the top maybe? That might to do it.
Well, right now it’s unconditional, but i’m just starting it. It’s actually going to be a mesh collider and a few conditions will determine what mesh that collider will use.
Though thank you. I wasn’t sure if the OnDrawGizmos() method was what i needed.