using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class adjustscale : MonoBehaviour
{
public float rotationMin = 0.0f;
public float rotationMax = 45.0f;
public Slider scale;
public Slider rotate;
[SerializeField] float currentRotation = 0f;
[SerializeField] float currentScale = 0f;
// Start is called before the first frame update
void Start()
{
rotate = GameObject.Find("rotate").GetComponent<Slider>();
scale = GameObject.Find("scale").GetComponent<Slider>();
}
// Update is called once per frame
void Update()
{
transform.localEulerAngles = new Vector3(0.0f, rotate.value, 0.0f);
transform.localScale = new Vector3(scale.value, scale.value, scale.value);
}
private void OnGUI()
{
currentRotation = GUI.HorizontalSlider(new Rect(-280.0f, 165.0f, 228.0f, 57.0f), currentRotation, 0.0f, 45.0f);
transform.localEulerAngles = new Vector3(0.0f, currentRotation, 0.0f);
currentScale = GUI.HorizontalSlider(new Rect(-280.0f, 120.0f, 228.0f, 57.0f), currentScale, 0.0f, 2.0f);
transform.localScale = new Vector3(currentScale, currentScale, currentScale);
}
public void AdjustAngle(float newAngle)
{ }
public void AdjustScale(float newScale)
{ }
}
Your script has:
[SerializeField] float currentScale = 0f;
So unless you change the value in the inspector, currentScale = 0;
Then in the last line of the OnGUI() method you set the scale to currentScale, which is 0 unless you have set it to something else in the inspector.
As you can see from Unity - Manual: Order of execution for event functions onGUI takes place after Update and LateUpdate.
HTH
Al
thanks @AITheSlacker
can you answer my next question?