某项目控制滑条上下滑动

代码直接挂在 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()
    {
       
    }

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值