Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using UnityEngine;
- public class SurvivalGrapplingHook : MonoBehaviour
- {
- private enum eGrappleState
- {
- ePutAway,
- eFiring,
- eImpacted,
- eReelingIn
- }
- private SurvivalGrapplingHook.eGrappleState meState;
- private GameObject GrapplingHookInstance;
- private Vector3 mPlayerOverridePos;
- private Vector3 mVecToHook;
- private Vector3 mNormVecToHook;
- private float mrWinchDist;
- private void Start()
- {
- this.GrapplingHookInstance = GameObject.Find("GrappleHookPrefab");
- this.GrapplingHookInstance.SetActive(false);
- this.meState = SurvivalGrapplingHook.eGrappleState.ePutAway;
- }
- private void Update()
- {
- if (UIManager.mbEditingTextField || global::Console.IsOpen)
- {
- return;
- }
- if (Input.GetButtonDown("Grappling Hook") && this.meState == SurvivalGrapplingHook.eGrappleState.ePutAway)
- {
- Debug.Log("Firing grappling hook!");
- this.GrapplingHookInstance.transform.position = WorldScript.instance.localPlayerInstance.transform.position + Vector3.up;
- this.GrapplingHookInstance.transform.forward = WorldScript.instance.localPlayerInstance.mForwards;
- this.GrapplingHookInstance.GetComponent<GrappleHookScript>().Prepare();
- this.GrapplingHookInstance.SetActive(true);
- this.meState = SurvivalGrapplingHook.eGrappleState.eFiring;
- }
- if (this.meState == SurvivalGrapplingHook.eGrappleState.eFiring && this.GrapplingHookInstance.GetComponent<GrappleHookScript>().mbImpacted)
- {
- float num = this.GrapplingHookInstance.transform.position.y - 1f;
- float y = WorldScript.instance.localPlayerInstance.transform.position.y;
- if (num < y)
- {
- this.GrapplingHookInstance.SetActive(false);
- this.meState = SurvivalGrapplingHook.eGrappleState.ePutAway;
- }
- else
- {
- this.mPlayerOverridePos = WorldScript.instance.localPlayerInstance.transform.position;
- this.mVecToHook = this.GrapplingHookInstance.transform.position - WorldScript.instance.localPlayerInstance.transform.position;
- this.mNormVecToHook = this.mVecToHook;
- this.mrWinchDist = this.mNormVecToHook.magnitude;
- this.mNormVecToHook /= this.mrWinchDist;
- this.meState = SurvivalGrapplingHook.eGrappleState.eReelingIn;
- WorldScript.instance.localPlayerInstance.mbGravity = false;
- }
- }
- if (this.meState == SurvivalGrapplingHook.eGrappleState.eReelingIn)
- {
- WorldScript.instance.localPlayerInstance.mPosition = this.mPlayerOverridePos;
- float num2 = 35f;
- this.mPlayerOverridePos += this.mNormVecToHook * Time.deltaTime * num2;
- this.mrWinchDist -= Time.deltaTime * num2;
- if (this.mrWinchDist <= 1.5f)
- {
- WorldScript.instance.localPlayerInstance.mVelocity = Vector3.zero;
- WorldScript.instance.localPlayerInstance.mbGravity = true;
- this.GrapplingHookInstance.SetActive(false);
- this.meState = SurvivalGrapplingHook.eGrappleState.ePutAway;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment