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().color = new Color(gameObject.GetComponent().color.r, gameObject.GetComponent().color.g, gameObject.GetComponent().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().color = new Color(gameObject.GetComponent().color.r, gameObject.GetComponent().color.g, gameObject.GetComponent().color.b, alpha);
}
}
if (timer > waittime + time)
{
workingstatus = false;
}
}
}
在其他脚本调用以下代码
guidetip.GetComponent().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().color = new Color(gameObject.GetComponent().color.r, gameObject.GetComponent().color.g, gameObject.GetComponent().color.b, alpha);
}
if(timer>waittime+time)
{
workingstatus = false;
}
}
}
}
在其他脚本调用以下代码
guidemask.GetComponent().workingstatus = true;
手动调节图片透明度



