实现类似饥荒的夜晚效果:点击区域变亮,松开时又变暗。
using UnityEngine;
public class SG_13 : MonoBehaviour
{
Material mat;
string size = "_Size";
float sizeValue;
string pos = "_Pos";
Vector3 posValue=new Vector3(0.5f,0.5f,0);
public float speed = 1;
public Material Mat
{
get
{
if (mat == null)
{
mat = GetComponent<MeshRenderer>().material;
}
return mat;
}
set
{
mat = value;
}
}
void Update()
{
if (Input.GetMouseButton(0))
{
if (sizeValue < 1)
{
sizeValue += Time.deltaTime * speed;
sizeValue = Mathf.Min(1, sizeValue);
Mat.SetFloat(size, sizeValue);
posValue.Set(0.5f - Input.mousePosition.x/Screen.width, 0.5f-Input.mousePosition.y/Screen.height,0);
Mat.SetVector(pos, posValue);
}
}
else
{
if (sizeValue > 0)
{
sizeValue -= Time.deltaTime*speed;
sizeValue = Mathf.Max(0, sizeValue);
Mat.SetFloat(size, sizeValue);
}
}
}
}
返回目录:https://blog.csdn.net/yzy1987523/article/details/106676451