# How can I make that also the yradius values will change when the flag is true?

In this part when I'm changing the xradius slider it's also changing the yradius slider at the same time and same value. But I can't change the yradius when trying to change it's slider. I want to be able either change the xradius or yradius when the flag is true. Both will change to the same values but I want to be able to change also the yradius so it will change the xradius.

if (changeBothRadius)
{
}


I tried to add the xradius = yradius; but it's not working only when changing the xraiuds it's working.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

[RequireComponent(typeof(LineRenderer))]
public class DrawCircle : MonoBehaviour
{
[Range(0, 50)]
public int segments = 50;
[Range(1, 50)]
[Range(1, 50)]
[Range(0.1f, 2)]
public float lineThickness = 0.1f;

private LineRenderer line;
private List<float> radiusList = new List<float>();

void Start()
{
line = gameObject.GetComponent<LineRenderer>();
line.positionCount = segments + 1;
line.useWorldSpace = false;
CreatePoints();
}

void Update()
{
line.startWidth = lineThickness;
line.endWidth = lineThickness;
CreatePoints();
}

void CreatePoints()
{
{
}

float x;
float z;

float angle = 20;

for (int i = 0; i < (segments + 1); i++)
{

line.SetPosition(i, new Vector3(x, 0, z));

angle += (360f / segments + 1);
}
}
}


Remember, code is just a set of instructions that the computer follows literally. It doesn't read ahead to try to infer your intention.

So let's say xradius = 5 and yradius = 5 and you change the yradius slider to 7. The first command the CPU gets to is:

yradius = xradius;


So it dutifully follows this instruction, and undoes the change you made with the slider, setting yradius to 5, since that's the value of xradius. Only after it's done that does it reach this line:

xradius = yradius;


...which is now completely redundant because both variables already have the same value of 5.

In order to react the way you expect to either radius changing, it needs to have some memory of what the old values were, so it knows which one changed and can apply that one's value to the unchanged one.

If you're just changing these values in the inspector, then resetting the points every frame in Update() is a bit wasteful, and we can do it in OnValidate() instead to react only when an inspector value has changed in a way that might force us to re-generate our points:

Vector2 _cachedRadii;
Vector3[] _points;

void OnValidate() {
if(line == null)
line = GetComponent<LineRenderer>();

line.startWidth = lineThickness;
line.endWidth = lineThickness;

bool regenPoints = false;

if(_points == null || _points.Length != segments + 1) {
_points = new Vector3[segments + 1];
regenPoints = true;
}

regenPoints = true;
}
regenPoints = true;
}

if(regenPoints)
CreatePoints();
}

void CreatePoints()
{
float angle = 20;

for (int i = 0; i < (segments + 1); i++)
{

_points[i] = new Vector3(x, 0, z);

angle += (360f / segments + 1);
}

if(line.positionCount != _points.Length)
line.positionCount = _points.Length;
line.SetPositions(_points);

// Remember the last radii we used to generate points.