Godcraft

Untitled

Jun 27th, 2015
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.83 KB | None | 0 0
  1. using System;
  2. using UnityEngine;
  3. public class SurvivalGrapplingHook : MonoBehaviour
  4. {
  5.     private enum eGrappleState
  6.     {
  7.         ePutAway,
  8.         eFiring,
  9.         eImpacted,
  10.         eReelingIn
  11.     }
  12.     private SurvivalGrapplingHook.eGrappleState meState;
  13.     private GameObject GrapplingHookInstance;
  14.     private Vector3 mPlayerOverridePos;
  15.     private Vector3 mVecToHook;
  16.     private Vector3 mNormVecToHook;
  17.     private float mrWinchDist;
  18.     private void Start()
  19.     {
  20.         this.GrapplingHookInstance = GameObject.Find("GrappleHookPrefab");
  21.         this.GrapplingHookInstance.SetActive(false);
  22.         this.meState = SurvivalGrapplingHook.eGrappleState.ePutAway;
  23.     }
  24.     private void Update()
  25.     {
  26.         if (UIManager.mbEditingTextField || global::Console.IsOpen)
  27.         {
  28.             return;
  29.         }
  30.         if (Input.GetButtonDown("Grappling Hook") && this.meState == SurvivalGrapplingHook.eGrappleState.ePutAway)
  31.         {
  32.             Debug.Log("Firing grappling hook!");
  33.             this.GrapplingHookInstance.transform.position = WorldScript.instance.localPlayerInstance.transform.position + Vector3.up;
  34.             this.GrapplingHookInstance.transform.forward = WorldScript.instance.localPlayerInstance.mForwards;
  35.             this.GrapplingHookInstance.GetComponent<GrappleHookScript>().Prepare();
  36.             this.GrapplingHookInstance.SetActive(true);
  37.             this.meState = SurvivalGrapplingHook.eGrappleState.eFiring;
  38.         }
  39.         if (this.meState == SurvivalGrapplingHook.eGrappleState.eFiring && this.GrapplingHookInstance.GetComponent<GrappleHookScript>().mbImpacted)
  40.         {
  41.             float num = this.GrapplingHookInstance.transform.position.y - 1f;
  42.             float y = WorldScript.instance.localPlayerInstance.transform.position.y;
  43.             if (num < y)
  44.             {
  45.                 this.GrapplingHookInstance.SetActive(false);
  46.                 this.meState = SurvivalGrapplingHook.eGrappleState.ePutAway;
  47.             }
  48.             else
  49.             {
  50.                 this.mPlayerOverridePos = WorldScript.instance.localPlayerInstance.transform.position;
  51.                 this.mVecToHook = this.GrapplingHookInstance.transform.position - WorldScript.instance.localPlayerInstance.transform.position;
  52.                 this.mNormVecToHook = this.mVecToHook;
  53.                 this.mrWinchDist = this.mNormVecToHook.magnitude;
  54.                 this.mNormVecToHook /= this.mrWinchDist;
  55.                 this.meState = SurvivalGrapplingHook.eGrappleState.eReelingIn;
  56.                 WorldScript.instance.localPlayerInstance.mbGravity = false;
  57.             }
  58.         }
  59.         if (this.meState == SurvivalGrapplingHook.eGrappleState.eReelingIn)
  60.         {
  61.             WorldScript.instance.localPlayerInstance.mPosition = this.mPlayerOverridePos;
  62.             float num2 = 35f;
  63.             this.mPlayerOverridePos += this.mNormVecToHook * Time.deltaTime * num2;
  64.             this.mrWinchDist -= Time.deltaTime * num2;
  65.             if (this.mrWinchDist <= 1.5f)
  66.             {
  67.                 WorldScript.instance.localPlayerInstance.mVelocity = Vector3.zero;
  68.                 WorldScript.instance.localPlayerInstance.mbGravity = true;
  69.                 this.GrapplingHookInstance.SetActive(false);
  70.                 this.meState = SurvivalGrapplingHook.eGrappleState.ePutAway;
  71.             }
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment