For some reason when I'm using the mouse to change the radius in the Update, the minimum radius is -1 even if I set the range in the top of the script to be 0,50 and even if I check that the xradius is be 0 or higher it's still getting to -1.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System;
[RequireComponent(typeof(LineRenderer))]
public class DrawCircle : MonoBehaviour
{
[Range(0, 50)]
public int segments = 50;
public bool circle = true;
[Range(0, 50)]
public float xradius = 15;
[Range(0, 50)]
public float yradius = 15;
LineRenderer line;
public float drawSpeed = 0.3f;
void Start()
{
line = gameObject.GetComponent<LineRenderer>();
line.positionCount = (segments + 1);
line.useWorldSpace = false;
}
private void Update()
{
if (xradius >= 0)
{
if (Input.GetAxis("Mouse X") < 0)
{
xradius = xradius + 1;
CreatePoints();
}
if (Input.GetAxis("Mouse X") > 0)
{
xradius = xradius - 1;
CreatePoints();
}
}
}
private void CreatePoints()
{
if (circle == true)
yradius = xradius;
float x;
float z;
float change = 2 * (float)Math.PI / segments;
float angle = change;
for (int i = 0; i < (segments + 1); i++)
{
x = Mathf.Sin(angle) * xradius;
z = Mathf.Cos(angle) * yradius;
line.SetPosition((int)i, new Vector3(x, 0.5f, z));
angle += change;
}
}
}
In the Update I did:
if (xradius >= 0)
But yet when using the mouse for the minimum radius it set both xradius and yradius in the sliders to -1 not sure how can it be -1 if I set the range in both xradius and yradius to be 0,50
You can see in the screenshot in the Inspector in the right both Xradius and Yradius are -1