Hello ! I have a script for draw a circle like : Code (CSharp): using UnityEngine; using System.Collections; public class DrawCircle : MonoBehaviour { public int segments; public float xradius; public float yradius; LineRenderer line; void Start () { line = gameObject.GetComponent<LineRenderer>(); line.numPositions = segments + 1; line.useWorldSpace = false; CreatePoints (); } void CreatePoints () { float x; float y; float z = 0f; float angle = 20f; for (int i = 0; i < (segments + 1); i++) { x = Mathf.Sin (Mathf.Deg2Rad * angle) * xradius; y = Mathf.Cos (Mathf.Deg2Rad * angle) * yradius; line.SetPosition (i,new Vector3(x,y,z) ); angle += (360f / segments); } } } This code is working, If I attach my script on a GameObject, I have a circle drawn around my GameObject like in pink : My question is, how can I change the center of mycircle ? It's always the center of the GameObject, Is there a way to change that ? Thanks you
This should work (where middle will be an offset from the center of your GameObject): Code (CSharp): void CreatePoints (Vector2 middle) { float x; float y; float z = 0f; float angle = 20f; for (int i = 0; i < (segments + 1); i++) { x = middle.x + Mathf.Sin (Mathf.Deg2Rad * angle) * xradius; y = middle.y + Mathf.Cos (Mathf.Deg2Rad * angle) * yradius; line.SetPosition (i,new Vector3(x,y,z) ); angle += (360f / segments); } }