using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Manager : MonoBehaviour
{
public GameObject displayslider;
public GameObject TimeGetAngle;
public float TimeAngle, display;
public Text displayvaluetext, TimeAngletext;
public static Manager instance = null;
void Awake()
{
if (instance == null)
instance = this;
else if (instance != this)
Destroy(gameObject);
DontDestroyOnLoad(gameObject);
TimeAngle = 0;
display = 5;
}
void Start()
{
displayslider = GameObject.Find("displayslider");
Debug.LogError("", displayslider);
TimeGetAngle = GameObject.Find("Canvas/Panel/TimeGetAngle");
TimeAngletext = GameObject.Find("Canvas/Panel/TimeAngletext").GetComponent<Text>();
displayvaluetext = GameObject.Find("Canvas/Panel/displayvaluetext").GetComponent<Text>();
TimeAngletext.text = "" + TimeGetAngle.GetComponent<Slider>().value;
displayvaluetext.text = "" + displayslider.GetComponent<Slider>().value;
}
public void TimeGetAngleselect()
{
TimeAngle = TimeGetAngle.GetComponent<Slider>().value;
TimeAngletext.text = "" + TimeAngle;
}
public void Displayselect()
{
Debug.LogError("", displayslider);
display = displayslider.GetComponent<Slider>().value;
displayvaluetext.text = "" + display;
}
}
我在预制件中有这两个滑块,我想制作它,以便当我更改其中一个的值时,它旁边的文本框会显示该值。因此,当滑块更改值时,它会调用DisplaySelect()
方法。对于预设值,它可以正常工作,但是当我更改滑块中的值时,会出现以下错误:
UnassignedReferenceException:尚未分配Manager的变量displayslider。您可能需要在检查器中分配Manager脚本的displayslider变量