- Home /
How do I create basic 2D shapes in script?
So I would like to create something like carykh's evolution simulator and I kinda already did it in Processing but I did not like Box2D and I want to do other stuff in Unity as well so I started Unity but I could not figure out or find any tutorials or videos that show me how to create a simple circle from only C# code. I do not want to use pictures of circles or the Unity GUI, because I want the circles to be dynamically colored and sized. The closest I got to it is this Medium article: https://medium.com/@hyperparticle/draw-2d-physics-shapes-in-unity3d-2e0ec634381c but to create a simple circle I found it too complicated.. I mean it should be like 3 lines of code IMO! Please, I need the simplest way to show a circle on the screen in Unity2D.
I am pretty sure that recreating mesh from the scratch will be massive overkill and you will definitely wrote more than 3 lines of code. You can dynamically color and size Sprite. Check the link below (skip the OnGUI method - it's not the case here).
https://docs.unity3d.com/ScriptReference/SpriteRenderer.html
You can create prefab containing SpriteRenderer and Instantiate it while mouse button is pressed. While moving the cursor you can resize the shape using transform.localScale
for example. Whenever you are holding the button you can colorize the object with SpriteRenderer.color
. Sky is the limit.
Your answer
Follow this Question
Related Questions
Why is my circle cast not going the full distance? 0 Answers
Ground dash is like a teleport 0 Answers
How can I modify the sprite of a particular Scriptable Tile in a Tilemap? 2 Answers
2D character movement is jittery (top-down) 1 Answer
How can i make my sprites look crisp like in scene mode ? 3 Answers