SHARE
TWEET

lockpick code

poboivin Feb 15th, 2017 18 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class LockPick : MonoBehaviour {
  6.  
  7.     public GameObject Pick;
  8.     public GameObject Lock;
  9.     public float winAngle = 90;
  10.     public float winAngleRange = 10;
  11.     public float TurnZoneFactor = 3f;
  12.     public float LockAngle = 90;
  13.     public float PickAngle = 0;
  14.  
  15.  
  16.     //debug transforms
  17.     public GameObject text;
  18.     public Transform winZone1;
  19.     public Transform winZone2;
  20.     public Transform turnZone1;
  21.     public Transform turnZone2;
  22.  
  23.     void UpdateDebugObj()
  24.     {
  25.  
  26.         winZone1.transform.rotation = Quaternion.Euler(0, 0, winAngle - winAngleRange);
  27.         winZone2.transform.rotation = Quaternion.Euler(0, 0, winAngle + winAngleRange);
  28.         turnZone1.transform.rotation = Quaternion.Euler(0, 0, winAngle - winAngleRange * TurnZoneFactor);
  29.         turnZone2.transform.rotation = Quaternion.Euler(0, 0, winAngle + winAngleRange * TurnZoneFactor);
  30.  
  31.     }
  32.     // Update is called once per frame
  33.     void Update()
  34.     {
  35.         if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.A))
  36.         {
  37.             if (
  38.             LockAngle > 85 ||
  39.             LockAngle / 90 > Mathf.Abs(Mathf.DeltaAngle(winAngle, PickAngle)) / (winAngleRange * TurnZoneFactor) ||
  40.             Mathf.Abs(Mathf.DeltaAngle(winAngle, PickAngle)) < winAngleRange
  41.             )
  42.             {
  43.                 LockAngle -= 2;
  44.             }
  45.             else
  46.             {
  47.                 LockAngle += 1;
  48.             }
  49.         }
  50.         else
  51.         {
  52.             PickAngle += -Input.GetAxis("Mouse X");
  53.             LockAngle += 1;
  54.         }
  55.  
  56.         if (LockAngle > 90)
  57.         {
  58.             LockAngle = 90;
  59.         }
  60.         if (LockAngle < 0)
  61.         {
  62.             LockAngle = 0;
  63.             text.SetActive(true);
  64.         }
  65.         Pick.transform.rotation = Quaternion.Euler(0, 0, PickAngle);
  66.         Lock.transform.rotation = Quaternion.Euler(0, 0, LockAngle);
  67.  
  68.         UpdateDebugObj();
  69.     }
  70. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top