3DTD/Assets/Scripts/Camera/WallOpacity.cs

52 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WallOpacity : MonoBehaviour
{
private float t;
private bool isShowing = true;
private float showFadeSpeed;
private float hideFadeSpeed;
private void Start()
{
t = 1;
}
void Update()
{
if (isShowing)
{
t += Time.deltaTime * showFadeSpeed;
}
else
{
t -= Time.deltaTime * hideFadeSpeed;
}
t = Mathf.Clamp(t, 0, 1);
Renderer renderer = GetComponent<Renderer>();
if (renderer != null)
{
var originalMat = renderer.material;
var originalColor = originalMat.color;
originalMat.color = new Color(originalColor.r, originalColor.g, originalColor.b, t);
renderer.material = originalMat;
}
}
public void ShowWall(float speed)
{
isShowing = true;
showFadeSpeed = speed;
}
public void HideWall(float speed)
{
isShowing = false;
hideFadeSpeed = speed;
}
}