Advertisement
lemansky

Untitled

Apr 11th, 2021 (edited)
987
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 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.  
  11.     private void Start()
  12.     {
  13.  
  14.     }
  15.     void Update()
  16.     {
  17.         if (Input.GetKeyDown(KeyCode.B))
  18.         {
  19.  
  20.             if (GetObjectAtTeleportDistance() != null)
  21.             {
  22.                 Blink();
  23.             }
  24.             else
  25.             {
  26.                 transform.position = transform.position + transform.forward * range;
  27.             }
  28.  
  29.         }
  30.  
  31.     }
  32.  
  33.     private GameObject GetObjectAtTeleportDistance()
  34.     {
  35.         Vector3 origin = transform.position;
  36.         Vector3 direction = transform.forward;
  37.         if (Physics.Raycast(origin, direction, out lastRaycastHit, range))
  38.         {
  39.             if (lastRaycastHit.collider.gameObject.name != "Platform")
  40.             {
  41.                 return lastRaycastHit.collider.gameObject;
  42.             }
  43.             else
  44.             {
  45.                 return null;
  46.             }
  47.         }
  48.         else
  49.         {
  50.             return null;
  51.         }
  52.     }
  53.  
  54.     private void Blink()
  55.     {
  56.         transform.position = lastRaycastHit.point + -lastRaycastHit.normal + Vector3.up;
  57.     }
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement