赞
踩
Sprite类型
绑定即可使用
物体被激活后立即执行
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
-
- public class transparency : MonoBehaviour
- {
- //等待时间
- public float waittime=0;
- //渐变时长
- public float time=0.5f;
- //定时器
- public float timer;
- //透明度 范围是0-1
- float alpha = 0.9f;
-
- // Start is called before the first frame update
- void Start()
- {
-
- }
-
- // Update is called once per frame
- void Update()
- {
- timer += Time.deltaTime;
- if(timer>waittime)
- {
- alpha = (time - (timer-waittime)) / time;
- gameObject.GetComponent<SpriteRenderer>().color = new Color(gameObject.GetComponent<SpriteRenderer>().color.r, gameObject.GetComponent<SpriteRenderer>().color.g, gameObject.GetComponent<SpriteRenderer>().color.b, alpha);
- }
- }
- }
被外界通知后即可生效
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
-
- public class transparency : MonoBehaviour
- {
- //等待时间
- public float waittime = 0;
- //渐变时长
- public float time = 0.5f;
- //定时器
- public float timer;
- //透明度 范围是0-1
- float alpha = 0.9f;
- //启用状态
- public bool workingstatus = false;
-
- // Start is called before the first frame update
- void Start()
- {
-
- }
-
- // Update is called once per frame
- void Update()
- {
- if(workingstatus == true)
- {
- timer += Time.deltaTime;
- if (timer > waittime)
- {
- alpha = (time - (timer - waittime)) / time;
- gameObject.GetComponent<SpriteRenderer>().color = new Color(gameObject.GetComponent<SpriteRenderer>().color.r, gameObject.GetComponent<SpriteRenderer>().color.g, gameObject.GetComponent<SpriteRenderer>().color.b, alpha);
- }
- }
- if (timer > waittime + time)
- {
- workingstatus = false;
- }
- }
- }
在其他脚本调用以下代码
guidetip.GetComponent<transparency>().workingstatus = true;
Image类型
绑定即可使用
被外界通知后即可生效
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
-
- public class transparency : MonoBehaviour
- {
- //等待时间
- public float waittime = 0;
- //渐变时长
- public float time = 0.5f;
- //定时器
- public float timer;
- //透明度 范围是0-1
- float alpha = 0.9f;
- //启用状态
- public bool workingstatus = false;
-
- // Start is called before the first frame update
- void Start()
- {
-
- }
-
- // Update is called once per frame
- void Update()
- {
- if(workingstatus==true)
- {
- timer += Time.deltaTime;
- if (timer > waittime)
- {
- alpha = (time - (timer - waittime)) / time;
- gameObject.GetComponent<Image>().color = new Color(gameObject.GetComponent<Image>().color.r, gameObject.GetComponent<Image>().color.g, gameObject.GetComponent<Image>().color.b, alpha);
- }
- if(timer>waittime+time)
- {
- workingstatus = false;
- }
- }
- }
- }
在其他脚本调用以下代码
guidemask.GetComponent<transparency>().workingstatus = true;
手动调节图片透明度
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。