您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
40 行
623 B
40 行
623 B
using UnityEngine;
|
|
|
|
public class StealthEffect : MonoBehaviour
|
|
{
|
|
MeshRenderer rend;
|
|
Material mat;
|
|
string propName = "_dissolve";
|
|
|
|
int dir = -1;
|
|
float elapsedTime;
|
|
|
|
private void Start()
|
|
{
|
|
rend = GetComponent<MeshRenderer>();
|
|
if (rend == null)
|
|
Destroy(this);
|
|
|
|
mat = rend.material;
|
|
elapsedTime = 1f;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (elapsedTime < 1)
|
|
{
|
|
elapsedTime += Time.deltaTime;
|
|
float val = Mathf.Lerp(dir == 1 ? 0 : 1, dir == 1 ? 1 : 0, elapsedTime);
|
|
|
|
mat.SetFloat(propName, val);
|
|
}
|
|
else
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.R))
|
|
{
|
|
elapsedTime = 0f;
|
|
dir *= -1;
|
|
}
|
|
}
|
|
}
|
|
}
|