- Home /
Increase the radius of Unity's primitive sphere?
How can I increase and decrease the radius of Unity's primitive sphere to my likings? I have to change the actual sphere, not the collider itself. I have searched google for this but they all are changing the actual collider, not the mesh. Thanks!!
Answer by robertbu · Nov 17, 2013 at 01:05 AM
Just change the localScale of the transform.
var go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
go.transform.localScale = Vector3(scale, scale, scale);
...where 'scale' is a variable or some constant.
Your question asks about changing the actual mesh. Is there some reason that you need to mesh rather than scaling the transform? If so does it have to be done at runtime?
Well I have a plane dead center of the sphere. The plane has a material on it that looks like a blue ring. I am using this ring as a sound wave that emits from the player. I want to increase the sphere's radius so that the ring inside of it will increase as well, and when it hit an enemy, he would be alerted. That is why I am using a sphere. Is there some better way to do this?
As you can see, there is a plane (as a child of the sphere) and that plane has a material that looks like a sound wave. I created the sphere it is parented to does not have a mesh render, so you can only see the sound wave. When the player walks, i want to increase the sphere, thus increasing the sound wave and the collider.
Changing the Transform.localScale of the sphere will scale the plane as well. But if the only reason to use the sphere is scaling, then you can delete the sphere and just change the localScale of the plane.
I am using the sphere so that anybody that touches the ring will be alerted that the player is near. Thanks for your help!