How can I check in the Update fro data changes ?

using UnityEngine;
using System.Collections;

[ExecuteAlways]

[RequireComponent(typeof(LineRenderer))]
public class DrawRadiusAroundTurret : MonoBehaviour
{
    [Range(0, 50)]
    public int segments = 50;
    [Range(0, 5)]
    public float xradius = 5;
    [Range(0, 5)]
    public float yradius = 5;
    [Range(0.1f, 5f)]
    public float width = 0.1f;
    LineRenderer line;
    public bool controlBothXradiusYradius = false;

    void Start()
    {
        line = gameObject.GetComponent<LineRenderer>();

        line.enabled = true;
        line.positionCount = segments + 1;
        line.widthMultiplier = width;
        line.useWorldSpace = false;
        CreatePoints();
    }

    private void Update()
    {
        CreatePoints();
    }

    public void CreatePoints()
    {
        line.widthMultiplier = width;

        float x;
        float y;
        float z;

        float angle = 20f;

        if (controlBothXradiusYradius == true)
        {
            yradius = xradius;
        }

        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, 0f, y));

            angle += (380f / segments);
        }
    }

    private void OnValidate()
    {
        if (controlBothXradiusYradius == true)
        {
            yradius = xradius;
        }
    }
}

Calling CreatePoints in the Update is working but it’s not a good idea. What variables values changes should I check and how in the Update before calling the CreatePoints ? I want to be able to change the turret data in real time in editor mode and runtime mode.

I believe I suggested to you precisely how to do this just yesterday:

https://discussions.unity.com/t/801595/2

Were you unable to do that?

1 Like

Sorry forgot to check the other thread.

Thank you.