Advertisement
lemansky

Untitled

Apr 11th, 2021
876
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class LerpLight : MonoBehaviour
  6. {
  7.  
  8.     public float progress;
  9.     public float speed = 0.5f;
  10.     bool _checker = true;
  11.     Light _myLight;
  12.     Quaternion _originalRotation;
  13.     Vector3 _originalPosition;
  14.     public Color lerpColorFrom;
  15.     public Color lerpColorTo;
  16.     void Start()
  17.     {
  18.         _originalPosition = transform.position;
  19.         _originalRotation = transform.rotation;
  20.         _myLight = GetComponent<Light>();
  21.     }
  22.  
  23.     void Update()
  24.     {
  25.         if (_checker)
  26.         {
  27.             progress = progress + speed * Time.deltaTime;
  28.             progress = Mathf.Clamp01(progress);
  29.             _myLight.color = Color.Lerp(lerpColorFrom, lerpColorTo, progress);
  30.             //transform.rotation = Quaternion.Slerp(_originalRotation, Quaternion.identity, progress);
  31.             //transform.position = Vector3.Lerp(_originalPosition, Vector3.zero, progress);
  32.         }
  33.         else
  34.         {
  35.             progress = progress + speed * Time.deltaTime;
  36.             progress = Mathf.Clamp01(progress);
  37.             _myLight.color = Color.Lerp(lerpColorTo, lerpColorFrom, progress);
  38.             //transform.rotation = Quaternion.Slerp(Quaternion.identity, _originalRotation, progress);
  39.             //transform.position = Vector3.Lerp(Vector3.zero, _originalPosition, progress);
  40.  
  41.         }
  42.  
  43.         if (progress == 1)
  44.         {
  45.             _checker = !_checker;
  46.             progress = 0;
  47.         }
  48.  
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement