Advertisement
BlackDragonBE

WeepingAngel.cs

Jan 21st, 2018
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. [RequireComponent(typeof(VisibleOrNot))]
  6. public class WeepingAngel : MonoBehaviour
  7. {
  8.     private VisibleOrNot _visibleOrNot;
  9.  
  10.     private void Awake()
  11.     {
  12.         _visibleOrNot = GetComponent<VisibleOrNot>();
  13.     }
  14.  
  15.     // Use this for initialization
  16.     private void Start()
  17.     {
  18.     }
  19.  
  20.     // Update is called once per frame
  21.     private void Update()
  22.     {
  23.         if (!_visibleOrNot.IsVisible)
  24.         {
  25.             Vector3 targetDir = Camera.main.transform.position - transform.position;
  26.             float step = .5f * Time.deltaTime;
  27.             Vector3 newDir = Vector3.RotateTowards(transform.forward, targetDir, step, 0.0F);
  28.             transform.rotation = Quaternion.LookRotation(newDir);
  29.  
  30.             transform.position = Vector3.MoveTowards(transform.position, Camera.main.transform.position, .5f * Time.deltaTime);
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement