首页 > 其他 > 详细

进度条

时间:2021-06-22 15:16:57      阅读:18      评论:0      收藏:0      [点我收藏+]

主要内容:实现点击物体后,销毁物体,记录销毁数量,进度条做出相应改变(如下图)

技术分享图片

 

 面板与代码如下:

技术分享图片

 

 

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

public class ChangeValue : MonoBehaviour
{
    Text text ;
    int a = 0;
    Image amount;
    GameObject cubes;

    // Start is called before the first frame update
    void Start()
    {
        text = transform.Find("Text").GetComponent<Text>();
        text.text = a + "";
        amount = transform.Find("Blood/BloodValue").GetComponent<Image>();
        amount.fillAmount = 0;
        cubes = GameObject.Find("GameObject");
    }


    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hitInfo;
            if (Physics.Raycast(ray, out hitInfo))
            {
                Destroy(hitInfo.transform.gameObject);
                text.text = ++a +"";
                amount.fillAmount = amount.fillAmount + ((1.0f / cubes.GetComponentsInChildren<Transform>().Length));

            }
        }
    }
}

代码解释:利用射线检测获取物体信息。

进度条

原文:https://www.cnblogs.com/gyjldlhiahia/p/14917824.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!