lemansky

Untitled

Apr 11th, 2021 (edited)
1,033
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class Skills : MonoBehaviour
  7. {
  8.     RaycastHit lastRaycastHit;
  9.     public float range = 20.0f;
  10.     public float blinkRate = 2f;
  11.     public float blinkCooldown = -1.0f;
  12.  
  13.  
  14.     private void Start()
  15.     {
  16.  
  17.     }
  18.     void Update()
  19.     {
  20.         if (Input.GetKeyDown(KeyCode.B))
  21.         {
  22.             if (Time.time > blinkCooldown)
  23.             {
  24.                 if (GetObjectAtTeleportDistance() != null)
  25.                 {
  26.                     Blink();
  27.                 }
  28.                 else
  29.                 {
  30.                     transform.position = transform.position + transform.forward * range;
  31.                 }
  32.                 blinkCooldown = Time.time + blinkRate;
  33.             }
  34.         }
  35.        
  36.     }
  37.  
  38.     private GameObject GetObjectAtTeleportDistance()
  39.     {
  40.         Vector3 origin = transform.position;
  41.         Vector3 direction = Camera.main.transform.forward;
  42.         if(Physics.Raycast(origin, direction, out lastRaycastHit, range))
  43.         {
  44.             if(lastRaycastHit.collider.gameObject.name != "Platform")
  45.             {
  46.                 return lastRaycastHit.collider.gameObject;
  47.             }
  48.             else
  49.             {
  50.                 return null;
  51.             }
  52.         }
  53.         else
  54.         {
  55.             return null;
  56.         }
  57.     }
  58.  
  59.     private void Blink()
  60.     {
  61.         transform.position = lastRaycastHit.point + -lastRaycastHit.normal + Vector3.up;
  62.     }
  63. }
  64.  
Add Comment
Please, Sign In to add comment