Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // script that fades over time when pressed T or whatever the option you like use it to fade an object
- //
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class FadeObject : MonoBehaviour {
- void update ()
- {
- if(Input.GetKeyUp(KeyCode.T))
- {
- StartCoroutine(FadeTo(0.0f, 1.0f));
- }
- if(Input.GetKeyUp(KeyCode.F))
- {
- StartCoroutine(FadeTo(1.0f, 1.0f));
- }
- }
- IEnumerator FadeTo(float aValue, float aTime)
- {
- float alpha = transform.GetComponent<Renderer>().material.color.a;
- for (float t = 0.0f; t < 1.0f; t += Time.deltaTime / aTime)
- {
- Color newColor = new Color(1, 1, 1, Mathf.Lerp(alpha,aValue,t));
- transform.GetComponent<Renderer>().material.color = newColor;
- yield return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement