using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FanYe : MonoBehaviour
{
int index = 0;
public Text text;
// Use this for initialization
void Start()
{
AnNiu();
}
//翻页按钮
public Button zuo;
public Button you;
// Update is called once per frame
void Update()
{
}
//UI翻页通用格式
void OpenSigle(int index = 0)
{
for (int i = 0; i < transform.childCount; i++)
{
transform.GetChild(i).gameObject.SetActive(false);
}
transform.GetChild(index).gameObject.SetActive(true);
}
void AnNiu()
{
//页数为1,隐藏翻页按钮
if (transform.childCount == 1)
{
zuo.gameObject.SetActive(false);
you.gameObject.SetActive(false);
}
OpenSigle();
zuo.onClick.AddListener(delegate
{
if (index > 0)
index--;
OpenSigle(index);
//翻页文字变化
text.text = (index + 1) + "/" + transform.childCount;
});
you.onClick.AddListener(delegate
{
if (index < transform.childCount - 1)
index++;
OpenSigle(index);
text.text = (index + 1) + "/" + transform.childCount;
});
}
}