Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class Skills : MonoBehaviour
- {
- RaycastHit lastRaycastHit;
- public float range = 20.0f;
- public float blinkRate = 2f;
- public float blinkCooldown = -1.0f;
- private void Start()
- {
- }
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.B))
- {
- if (Time.time > blinkCooldown)
- {
- if (GetObjectAtTeleportDistance() != null)
- {
- Blink();
- }
- else
- {
- transform.position = transform.position + transform.forward * range;
- }
- blinkCooldown = Time.time + blinkRate;
- }
- }
- }
- private GameObject GetObjectAtTeleportDistance()
- {
- Vector3 origin = transform.position;
- Vector3 direction = Camera.main.transform.forward;
- if(Physics.Raycast(origin, direction, out lastRaycastHit, range))
- {
- if(lastRaycastHit.collider.gameObject.name != "Platform")
- {
- return lastRaycastHit.collider.gameObject;
- }
- else
- {
- return null;
- }
- }
- else
- {
- return null;
- }
- }
- private void Blink()
- {
- transform.position = lastRaycastHit.point + -lastRaycastHit.normal + Vector3.up;
- }
- }
Add Comment
Please, Sign In to add comment