Advertisement
Guest User

GrapplingHookScript

a guest
Jul 20th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityStandardAssets.Characters.FirstPerson;
  5.  
  6. public class GrapplingHook : MonoBehaviour {
  7.  
  8.     public Camera cam;
  9.     public RaycastHit hit;
  10.  
  11.     public LayerMask cullingmask;
  12.     public int Maxdistance;
  13.  
  14.     public bool IsFlying;
  15.     public Vector3 loc;
  16.  
  17.     public float speed = 10;
  18.     public Transform hand;
  19.  
  20.     public FirstPersonController FPC;
  21.     public LineRenderer LR;
  22.     // Use this for initialization
  23.     void Start ()
  24.     {
  25.         Cursor.lockState = CursorLockMode.Locked;
  26.     }
  27.    
  28.     // Update is called once per frame
  29.     void Update ()
  30.     {
  31.         if (Input.GetKey (KeyCode.Q))
  32.             Findspot ();
  33.  
  34.         if (IsFlying)
  35.             Flying ();
  36.         if(Input.GetKey(KeyCode.Space) && IsFlying)
  37.         {
  38.             IsFlying = false;
  39.             FPC.canMove = true;
  40.             LR.enabled = false;
  41.         }
  42.     }
  43.     public void Findspot ()
  44.     {
  45.         if (Physics.Raycast (cam.transform.position, cam.transform.forward, out hit, Maxdistance, cullingmask)) {
  46.             IsFlying = true;
  47.             loc = hit.point;
  48.             FPC.canMove = false;
  49.             LR.enabled = true;
  50.             LR.SetPosition (1, loc);
  51.         }
  52.     }
  53.  
  54.     public void Flying()
  55.     {
  56.         transform.position = Vector3.Lerp(transform.position, loc, speed * Time.deltaTime / Vector3.Distance(transform.position, loc));
  57.         LR.SetPosition(0, hand.position);
  58.  
  59.         if(Vector3.Distance(transform.position, loc) < 0.5f)
  60.         {
  61.             IsFlying = false;
  62.             FPC.canMove = true;
  63.             LR.enabled = false;
  64.         }  
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement