Search code examples
c#unity-game-engineunity-editor

Why does it not draw the circle gizmo in editor?


I am trying to draw a simple circle in the editor. I found this method but I don't understand why it doesn't work. How can I draw the circle in the editor? Thank you.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif

public class Assigments : MonoBehaviour
{
    Transform obj;

    [Range(0, 3f)]
    public float radious = 1f;

#if UNITY_EDITOR
    private void OnDrawGizmos()
    {
        Debug.Log("works");
        Vector2 origin = transform.position;
        Handles.color = Color.red;
        Handles.DrawWireDisc(origin, new Vector3(0, 0, 1), radious);
    }
#endif
}

Solution

  • Try this.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Assigments : MonoBehaviour
    {
        public float lookRadius = 10f;
        void OnDrawGizmosSelected()
        {
            Gizmos.color = Color.red;
            Gizmos.DrawWireSphere(transform.position, lookRadius);
        }
    }