Advertisement
salahzar

Gaze.cs

Apr 14th, 2020
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class Gaze : MonoBehaviour
  7. {
  8.  
  9.     public float totalTime = 2;
  10.     public float currentTime = 0;
  11.     public bool isActive = false;
  12.     public Image image;
  13.     public GameObject player;
  14.     // Start is called before the first frame update
  15.     void Start()
  16.     {
  17.        
  18.     }
  19.     public void EnableGaze()
  20.     {
  21.         isActive = true;
  22.         currentTime = 0;
  23.        
  24.     }
  25.     public void DisableGaze()
  26.     {
  27.         isActive = false;
  28.         image.fillAmount = 0;
  29.     }
  30.  
  31.     // Update is called once per frame
  32.     void Update()
  33.     {
  34.         if (isActive)
  35.         {
  36.             currentTime += Time.deltaTime;
  37.             image.fillAmount = currentTime / totalTime;
  38.         }
  39.         if(image.fillAmount == 1 && isActive)
  40.         {
  41.             isActive = false;
  42.             player.transform.position = new Vector3(transform.position.x, transform.position.y + 1.5f, transform.position.z);
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement