UGUI基础学习

 

目录

TEXT

IMAGE

ROWIMAGE


TEXT

fontsize:字体

color:字体颜色

;inespacing:字行间隔

 代码展示:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TEXTtest : MonoBehaviour
{
    private  Text text;

    void Start()
    {
        text = GameObject.FindGameObjectWithTag("text").GetComponent<Text>();
        setOnGui();

    }
    public void setOnGui()
    {
        text.text =  "这是运行后的效果";
        text.fontSize = 30;
        text.color = Color.red;
        text.lineSpacing = 2;
    }
}

效果展示 :

IMAGE

代码展示:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ImageTest : MonoBehaviour
{
    private Image image;
    public float CDtime=10f;   //CD总时间
    public float restTime = 10f;//CD剩余时间
    void Start()
    {
        image = GameObject.Find("CD").GetComponent<Image>();//在面板搜索名字为CD的物体 并获取image组件
    }

    void Update()
    {
        if (restTime > 0) 
        {               
            restTime -= Time.deltaTime; 
            image.fillAmount = restTime / CDtime; //剩余时间/CD总时间
            Debug.Log(restTime);
        }
    }
}

效果展示:

 

ROWIMAGE

代码展示:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class rawimage : MonoBehaviour
{
    private bool end = false;
    private int count;       //用于记录当前是第几次刷新
    private RawImage raw;
    public float timerintervl = 1f;
    private float timer = 0f;
    void Start()
    {
        raw = GetComponent<RawImage>();
        raw.uvRect = new Rect(new Vector2(0, 0.5f), new Vector2(0.25f, 0.5f));
    }
    void Update()
    {
        if (raw.uvRect.x >= 0.76&&!end ) 
        { 
            raw.uvRect = new Rect(new Vector2(0, 0), new Vector2(0.25f, 0.5f));
        }
        timer += Time.deltaTime;
        if (timer >= timerintervl&&!end)
        {
            raw.uvRect = new Rect(new Vector2(raw.uvRect.x + 0.19f, raw.uvRect.y), new Vector2(raw.uvRect.width,raw.uvRect.height));
            timer = 0;
            count++;
        }
        if (count >= 9) { end = true; }
    }
}

效果展示:随着代码的运行照片上的数字会一一显示出来,最终实现一个时间累加的动画。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值