【发布时间】:2020-09-03 03:10:26
【问题描述】:
我为我的关卡菜单下载了一个脚本,但是当我尝试该脚本时,我无法将我的滚动条分配给该脚本。我试图复制脚本并再次粘贴并制作一个新脚本,但它不起作用。我该如何解决?
using UnityEngine;
using UnityEngine.UI;
public class swipe_menu : MonoBehaviour
{
public GameObject scrollbar;
private float scrollpos = 0;
float[] pos;
void Start()
{
}
void Update()
{
pos = new float[transform.childCount];
float distance = 1f / (pos.Length - 1f);
for (int i = 0; i < pos.Length; i++)
{
pos[i] = distance * i;
}
if (Input.GetMouseButton(0))
{
scrollpos = scrollbar.GetComponent<Scrollbar>().value;
}
else
{
for (int i = 0; i < pos.Length; i++)
{
if (scrollpos < pos[i] + (distance / 2) && scrollpos > pos[i] - (distance / 2))
{
scrollbar.GetComponent<Scrollbar>().value = Mathf.Lerp(scrollbar.GetComponent<Scrollbar>().value, pos[i], 0.1f);
}
}
}
for (int i = 0; i < pos.Length; i++)
{
if (scrollpos < pos[i] + (distance / 2) && scrollpos > pos[i] - (distance / 2))
{
Debug.LogWarning("Current Selected Level" + i);
transform.GetChild(i).localScale = Vector2.Lerp(transform.GetChild(i).localScale, new Vector2(1.2f, 1.2f), 0.1f);
for (int j = 0; j < pos.Length; j++)
{
if (j != i)
{
transform.GetChild(j).localScale = Vector2.Lerp(transform.GetChild(j).localScale, new Vector2(0.8f, 0.8f), 0.1f);
}
}
}
}
}
【问题讨论】:
-
您在编辑器中有任何编译错误吗?查看控制台是否有任何无法清除的红色(这是我的猜测)。如果不确定,在尝试添加组件之前等待 unity 编译,如果仍然没有显示,最后关闭并重新启动 unity。
标签: c# unity3d user-interface 3d