代码直接挂在 Scroll View 中的Content上
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ViewTest : MonoBehaviour
{
// public RectTransform ac;
private float posy;
private float width;
private float height;
public bool isDo; //下翻页
public bool isGo; //上翻
public int Up;
public int down;
public float Speed;
void Start()
{
}
void Update()
{
if (isDo)
{
posy += Speed;
this.GetComponent<RectTransform>().anchoredPosition = new Vector2(0, posy); //++
height = this.GetComponent<RectTransform>().sizeDelta.y;
if (posy > height - Up)
{
posy += 0;
isDo = false;
}
}
if (isGo)
{
posy -= Speed;
this.GetComponent<RectTransform>().anchoredPosition = new Vector2(0, posy); //— —
height = this.GetComponent<RectTransform>().sizeDelta.y;
if (posy < 0 + down)
{
posy -= 0;
isGo = false;
}
}
}
public void OnEnable()
{
this.GetComponent<RectTransform>().anchoredPosition = new Vector2(0, 0);
Debug.Log("归零");
}
public void Reset1()
{
}
}