Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 49.07 KB | None | 0 0
  1. using UnityEngine;
  2. using Valve.VR;
  3.  
  4. public class ControllerScript : Photon.MonoBehaviour
  5. {
  6. public bool offHand;
  7.  
  8.  
  9. public SteamVR_Action_Vector2 _touchpadTouch;
  10.  
  11. private float sprint = 1;
  12. public float sprintMultiplier = 2;
  13. public float speed = 5;
  14.  
  15. private bool flight = false;
  16.  
  17. public GameObject thePlayer;
  18. public GameObject otherHand;
  19.  
  20. private bool twoHanded = false;
  21. public GameObject itemInHand;
  22.  
  23. public Transform playerHead;
  24. private float playerHeight;
  25. public float heightSpeedMultiplier = 2f;
  26. public float heightPow;
  27. public float sittingHeight;
  28. public float maxHeight;
  29.  
  30. public float gripDistance;
  31.  
  32. private int gripLevel = 1;
  33.  
  34. public GameObject radioGuider;
  35. //GRIP LEVEL 0: CANT USE BOLT
  36. //GRIP LEVEL 1: NEUTRAL: CAN GRAB ANYTHING
  37. //GRIP LEVEL 2: CAN ONLY MOVE BOLT
  38.  
  39. private bool gripRelease = true;
  40.  
  41. public bool isClimbing = false;
  42. public bool climbingBackup = false;
  43. public Vector3 ClimbVec;
  44. public Vector3 ClimbVecHand;
  45. public Quaternion ClimbQuat;
  46. public float ClimbingDistance;
  47. public float ClimbingMaxDistance;
  48.  
  49. public GameObject magBag;
  50. public GameObject weaponOnChest;
  51. public float chestRadius;
  52.  
  53. public Transform leftGripClimb;
  54. public Transform rightGripClimb;
  55.  
  56. public GameObject handLerper;
  57.  
  58.  
  59. void Update()
  60. {
  61.  
  62.  
  63. if (photonView.isMine)
  64. {
  65.  
  66. Vector2 touchpad = _touchpadTouch.GetAxis(SteamVR_Input_Sources.LeftHand);
  67.  
  68. Vector2 useTouch = _touchpadTouch.GetAxis(SteamVR_Input_Sources.Any);
  69.  
  70.  
  71. if ((((thePlayer.transform.position.y + playerHead.position.y) / 2) + 1.5f) * Mathf.Pow(heightSpeedMultiplier, heightPow) < maxHeight)
  72. {
  73. playerHeight = (((thePlayer.transform.position.y + playerHead.position.y) / 2) + 1.5f) * Mathf.Pow(heightSpeedMultiplier, heightPow);
  74. }
  75. else
  76. {
  77. playerHeight = maxHeight + 0.1f;
  78. }
  79.  
  80.  
  81.  
  82. //thePlayer.transform.position += Vector3.forward * Time.deltaTime * speed;
  83. //SPRINT TOGGLE
  84. //if (device.GetPressDown(touchpadButton))
  85.  
  86. if (SteamVR_Input._default.inActions.TouchpadPressed.GetState(SteamVR_Input_Sources.LeftHand) && playerHeight > sittingHeight)
  87. {
  88. sprint = sprintMultiplier;
  89. }
  90. else
  91. {
  92. sprint = 1;
  93. }
  94.  
  95.  
  96.  
  97. if (SteamVR_Input._default.inActions.TriggerPressed.GetStateUp(SteamVR_Input_Sources.LeftHand) && offHand && itemInHand != null)
  98. {
  99. if (itemInHand.name == "rifle bolt")
  100. {
  101. itemInHand.transform.parent.transform.parent.transform.parent.GetComponent<GunProperties>().boltIsHolding = false;
  102. gripLevel = 1;
  103. itemInHand = null;
  104. }
  105. }
  106.  
  107. if (SteamVR_Input._default.inActions.TriggerPressed.GetStateUp(SteamVR_Input_Sources.RightHand) && !offHand && itemInHand != null)
  108. {
  109. if (itemInHand.name == "rifle bolt")
  110. {
  111. itemInHand.transform.parent.transform.parent.transform.parent.GetComponent<GunProperties>().boltIsHolding = false;
  112. gripLevel = 1;
  113. itemInHand = null;
  114. }
  115. }
  116.  
  117. /*
  118. if (SteamVR_Input._default.inActions.TriggerPressed.GetState(SteamVR_Input_Sources.LeftHand))
  119. {
  120. flight = true;
  121. }
  122. else
  123. {
  124. flight = false;
  125. }
  126. */
  127.  
  128.  
  129.  
  130.  
  131. //MAG RELEASE FROM HAND
  132.  
  133. if (SteamVR_Input._default.inActions.TriggerPressed.GetStateUp(SteamVR_Input_Sources.RightHand) && itemInHand != null && !offHand && itemInHand.GetComponent<MagScript>() != null)
  134. {
  135. itemInHand.transform.GetComponent<MeshCollider>().enabled = true;
  136. itemInHand.GetComponent<Rigidbody>().useGravity = true;
  137. itemInHand.GetComponent<Rigidbody>().velocity = Vector3.zero;
  138. itemInHand.GetComponent<Rigidbody>().AddForce((handLerper.transform.forward * handLerper.transform.GetComponent<HandLerper>().force) / itemInHand.GetComponent<MagScript>().weight);
  139. itemInHand = null;
  140. gripLevel = 1;
  141. otherHand.GetComponent<ControllerScript>().gripLevel = 1;
  142. }
  143. if (SteamVR_Input._default.inActions.TouchpadPressed.GetStateDown(SteamVR_Input_Sources.RightHand) && itemInHand != null && itemInHand.GetComponent<GunProperties>() != null && useTouch.y < 0 && !offHand && itemInHand.GetComponent<GunProperties>().magIn)
  144. {
  145. itemInHand.GetComponent<GunProperties>().magIn = false;
  146. itemInHand.GetComponent<GunProperties>().sound.PlayOneShot(itemInHand.GetComponent<GunProperties>().snd_mag_out, 1);
  147. }
  148.  
  149. if (SteamVR_Input._default.inActions.TriggerPressed.GetStateUp(SteamVR_Input_Sources.LeftHand) && itemInHand != null && offHand && itemInHand.GetComponent<MagScript>() != null)
  150. {
  151. itemInHand.transform.GetComponent<MeshCollider>().enabled = true;
  152. itemInHand.GetComponent<Rigidbody>().useGravity = true;
  153. itemInHand.GetComponent<Rigidbody>().velocity = Vector3.zero;
  154. itemInHand.GetComponent<Rigidbody>().AddForce((handLerper.transform.forward * handLerper.transform.GetComponent<HandLerper>().force) / itemInHand.GetComponent<MagScript>().weight);
  155. itemInHand = null;
  156. gripLevel = 1;
  157. otherHand.GetComponent<ControllerScript>().gripLevel = 1;
  158. }
  159. if (SteamVR_Input._default.inActions.TouchpadPressed.GetStateDown(SteamVR_Input_Sources.LeftHand) && itemInHand != null && itemInHand.GetComponent<GunProperties>() != null && useTouch.y < 0 && offHand && itemInHand.GetComponent<GunProperties>().magIn)
  160. {
  161. itemInHand.GetComponent<GunProperties>().magIn = false;
  162. itemInHand.GetComponent<GunProperties>().sound.PlayOneShot(itemInHand.GetComponent<GunProperties>().snd_mag_out, 1);
  163. }
  164.  
  165. //RADIO RELEASE FROM HAND
  166.  
  167. if (SteamVR_Input._default.inActions.TriggerPressed.GetStateUp(SteamVR_Input_Sources.RightHand) && itemInHand != null && !offHand && itemInHand.GetComponent<RadioScript>() != null)
  168. {
  169. itemInHand.transform.GetComponent<RadioScript>().isTaken = false;
  170. itemInHand.transform.GetComponent<BoxCollider>().enabled = true;
  171. itemInHand.GetComponent<Rigidbody>().useGravity = true;
  172. itemInHand.GetComponent<Rigidbody>().velocity = Vector3.zero;
  173. itemInHand.GetComponent<Rigidbody>().AddForce((handLerper.transform.forward * handLerper.transform.GetComponent<HandLerper>().force) / itemInHand.GetComponent<RadioScript>().weight);
  174. itemInHand = null;
  175. gripLevel = 1;
  176. otherHand.GetComponent<ControllerScript>().gripLevel = 1;
  177. }
  178.  
  179. if (SteamVR_Input._default.inActions.TriggerPressed.GetStateUp(SteamVR_Input_Sources.LeftHand) && itemInHand != null && offHand && itemInHand.GetComponent<RadioScript>() != null)
  180. {
  181. itemInHand.transform.GetComponent<RadioScript>().isTaken = false;
  182. itemInHand.transform.GetComponent<BoxCollider>().enabled = true;
  183. itemInHand.GetComponent<Rigidbody>().useGravity = true;
  184. itemInHand.GetComponent<Rigidbody>().velocity = Vector3.zero;
  185. itemInHand.GetComponent<Rigidbody>().AddForce((handLerper.transform.forward * handLerper.transform.GetComponent<HandLerper>().force) / itemInHand.GetComponent<RadioScript>().weight);
  186. itemInHand = null;
  187. gripLevel = 1;
  188. otherHand.GetComponent<ControllerScript>().gripLevel = 1;
  189. }
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199. if (SteamVR_Input._default.inActions.TouchpadPressed.GetStateDown(SteamVR_Input_Sources.RightHand) && itemInHand != null && !offHand && itemInHand.GetComponent<GunProperties>() != null && useTouch.y > 0)
  200. {
  201. itemInHand.GetComponent<GunProperties>().quickChamber = false;
  202. itemInHand.GetComponent<GunProperties>().quickChamberRejected = true;
  203.  
  204. if (itemInHand.GetComponent<GunProperties>().ammo > 0)
  205. {
  206. itemInHand.GetComponent<GunProperties>().bulletInChamber = true;
  207. }
  208. }
  209.  
  210.  
  211. //MAG TO GUN
  212. /*
  213. if (itemInHand != null && offHand && itemInHand.GetComponent<GunProperties>() != null && otherHand.GetComponent<ControllerScript>().itemInHand != null && otherHand.GetComponent<ControllerScript>().itemInHand.GetComponent<MagScript>() != null)
  214. {
  215. Debug.Log("TESTING 1");
  216.  
  217. if (Vector3.Distance(itemInHand.transform.Find("rifle1/rifle body/magazineTransform").transform.position, otherHand.transform.position) < 0.1f)
  218. {
  219. Debug.Log("TESTING 2");
  220.  
  221.  
  222. otherHand.GetComponent<MagScript>().parentGun = itemInHand;
  223. }
  224. }
  225. */
  226.  
  227.  
  228.  
  229.  
  230. if (SteamVR_Input._default.inActions.TriggerPressed.GetStateDown(SteamVR_Input_Sources.RightHand) && itemInHand != null && !offHand && itemInHand.GetComponent<GunProperties>() != null)
  231. {
  232. itemInHand.GetComponent<GunProperties>().isShooting = true;
  233. itemInHand.GetComponent<GunProperties>().trigger_click = true;
  234. }
  235. else
  236. {
  237. if (SteamVR_Input._default.inActions.TriggerPressed.GetStateUp(SteamVR_Input_Sources.RightHand) && itemInHand != null && !offHand && itemInHand.GetComponent<GunProperties>() != null)
  238. {
  239. itemInHand.GetComponent<GunProperties>().isShooting = false;
  240. itemInHand.GetComponent<GunProperties>().trigger_click = false;
  241. }
  242. }
  243.  
  244. if (SteamVR_Input._default.inActions.TriggerPressed.GetStateDown(SteamVR_Input_Sources.LeftHand) && itemInHand != null && offHand && itemInHand.GetComponent<GunProperties>() != null)
  245. {
  246. itemInHand.GetComponent<GunProperties>().isShooting = true;
  247. itemInHand.GetComponent<GunProperties>().trigger_click = true;
  248. }
  249. else
  250. {
  251. if (SteamVR_Input._default.inActions.TriggerPressed.GetStateUp(SteamVR_Input_Sources.LeftHand) && itemInHand != null && offHand && itemInHand.GetComponent<GunProperties>() != null)
  252. {
  253. itemInHand.GetComponent<GunProperties>().isShooting = false;
  254. itemInHand.GetComponent<GunProperties>().trigger_click = false;
  255. }
  256. }
  257.  
  258.  
  259. //////////////////////GRIP
  260.  
  261. if (SteamVR_Input._default.inActions.GripPressed.GetStateDown(SteamVR_Input_Sources.LeftHand))
  262. {
  263. if (itemInHand != null && itemInHand.GetComponent<GunProperties>() != null)
  264. {
  265. if (twoHanded)
  266. {
  267. twoHanded = false;
  268. itemInHand.GetComponent<GunProperties>().useGrip = false;
  269. }
  270. else
  271. {
  272. Debug.Log("GRIPPED");
  273. twoHanded = true;
  274. /*
  275. if (otherHand.GetComponent<ControllerScript>().itemInHand != null && Vector3.Distance(otherHand.GetComponent<ControllerScript>().itemInHand.transform.Find("gripLeft").transform.position, transform.position) < gripDistance)
  276. {
  277. Debug.Log("GRIPPED");
  278. twoHanded = true;
  279. }
  280. */
  281. }
  282. }
  283. }
  284. if (SteamVR_Input._default.inActions.GripPressed.GetStateDown(SteamVR_Input_Sources.RightHand))
  285. {
  286. if (itemInHand != null && itemInHand.GetComponent<GunProperties>() != null)
  287. {
  288. if (twoHanded)
  289. {
  290. twoHanded = false;
  291. itemInHand.GetComponent<GunProperties>().useGrip = false;
  292. }
  293. else
  294. {
  295. Debug.Log("GRIPPED");
  296. twoHanded = true;
  297. /*
  298. if (Vector3.Distance(itemInHand.transform.Find("gripRight").transform.position, transform.position) < gripDistance && otherHand.GetComponent<ControllerScript>().itemInHand != null)
  299. {
  300. twoHanded = true;
  301. }
  302. */
  303. }
  304. }
  305. }
  306.  
  307. if (itemInHand != null && !offHand && itemInHand.GetComponent<GunProperties>() != null)
  308. {
  309. if (SteamVR_Input._default.inActions.GripPressed.GetStateDown(SteamVR_Input_Sources.RightHand))
  310. {
  311. if (Vector3.Distance(itemInHand.transform.position, weaponOnChest.transform.position) < chestRadius && weaponOnChest.GetComponent<WeaponOnChest>().currentWeaponOnChest == null)
  312. {
  313. itemInHand.transform.position = weaponOnChest.transform.position;
  314. itemInHand.transform.rotation = weaponOnChest.transform.rotation;
  315. weaponOnChest.GetComponent<WeaponOnChest>().currentWeaponOnChest = itemInHand;
  316. }
  317. else
  318. {
  319. itemInHand.transform.position = transform.position;
  320. itemInHand.transform.rotation = transform.rotation;
  321. weaponOnChest.GetComponent<WeaponOnChest>().currentWeaponOnChest = null;
  322. }
  323. gripRelease = false;
  324. twoHanded = false;
  325. itemInHand.GetComponent<Rigidbody>().useGravity = true;
  326. itemInHand.GetComponent<Rigidbody>().velocity = Vector3.zero;
  327. itemInHand.GetComponent<Rigidbody>().AddForce((handLerper.transform.forward * handLerper.transform.GetComponent<HandLerper>().force) / itemInHand.GetComponent<GunProperties>().weight);
  328. itemInHand.GetComponent<BoxCollider>().enabled = true;
  329. itemInHand.GetComponent<GunProperties>().isShooting = false;
  330. itemInHand.GetComponent<GunProperties>().useGrip = false;
  331. itemInHand.GetComponent<GunProperties>().isTaken = false;
  332. itemInHand.GetComponent<GunProperties>().trigger_click = false;
  333. itemInHand = null;
  334.  
  335. if (!isClimbing && !climbingBackup)
  336. {
  337. otherHand.transform.Find("LeftHand").transform.position = otherHand.transform.Find("EmptyTransform").transform.position;
  338. otherHand.transform.Find("LeftHand").transform.rotation = otherHand.transform.Find("EmptyTransform").transform.rotation;
  339.  
  340. transform.Find("RightHand").transform.position = transform.Find("EmptyTransform").transform.position;
  341. transform.Find("RightHand").transform.rotation = transform.Find("EmptyTransform").transform.rotation;
  342. }
  343. }
  344. }
  345. if (itemInHand != null && offHand && itemInHand.GetComponent<GunProperties>() != null)
  346. {
  347. if (SteamVR_Input._default.inActions.GripPressed.GetStateDown(SteamVR_Input_Sources.LeftHand))
  348. {
  349. if (Vector3.Distance(itemInHand.transform.position, weaponOnChest.transform.position) < chestRadius && weaponOnChest.GetComponent<WeaponOnChest>().currentWeaponOnChest == null)
  350. {
  351. itemInHand.transform.position = weaponOnChest.transform.position;
  352. itemInHand.transform.rotation = weaponOnChest.transform.rotation;
  353. weaponOnChest.GetComponent<WeaponOnChest>().currentWeaponOnChest = itemInHand;
  354. }
  355. else
  356. {
  357. itemInHand.transform.position = transform.position;
  358. itemInHand.transform.rotation = transform.rotation;
  359. weaponOnChest.GetComponent<WeaponOnChest>().currentWeaponOnChest = null;
  360. }
  361. gripRelease = false;
  362. twoHanded = false;
  363. itemInHand.GetComponent<Rigidbody>().useGravity = true;
  364. itemInHand.GetComponent<Rigidbody>().velocity = Vector3.zero;
  365. itemInHand.GetComponent<Rigidbody>().AddForce((handLerper.transform.forward * handLerper.transform.GetComponent<HandLerper>().force) / itemInHand.GetComponent<GunProperties>().weight);
  366. itemInHand.GetComponent<BoxCollider>().enabled = true;
  367. itemInHand.GetComponent<GunProperties>().isShooting = false;
  368. itemInHand.GetComponent<GunProperties>().useGrip = false;
  369. itemInHand.GetComponent<GunProperties>().isTaken = false;
  370. itemInHand.GetComponent<GunProperties>().trigger_click = false;
  371. itemInHand = null;
  372.  
  373. if (!isClimbing && !climbingBackup)
  374. {
  375. transform.Find("LeftHand").transform.position = transform.Find("EmptyTransform").transform.position;
  376. transform.Find("LeftHand").transform.rotation = transform.Find("EmptyTransform").transform.rotation;
  377.  
  378. otherHand.transform.Find("RightHand").transform.position = otherHand.transform.Find("EmptyTransform").transform.position;
  379. otherHand.transform.Find("RightHand").transform.rotation = otherHand.transform.Find("EmptyTransform").transform.rotation;
  380. }
  381. }
  382. }
  383.  
  384. if (SteamVR_Input._default.inActions.GripPressed.GetStateUp(SteamVR_Input_Sources.LeftHand) && offHand)
  385. {
  386. gripRelease = true;
  387. }
  388. if (SteamVR_Input._default.inActions.GripPressed.GetStateUp(SteamVR_Input_Sources.RightHand) && !offHand)
  389. {
  390. gripRelease = true;
  391. }
  392.  
  393.  
  394.  
  395.  
  396. //CLIMBING
  397.  
  398. if (SteamVR_Input._default.inActions.MenuPressed.GetStateDown(SteamVR_Input_Sources.RightHand) && isClimbing == false && !offHand)
  399. {
  400. if (otherHand.transform.GetComponent<ControllerScript>().isClimbing == true)
  401. {
  402. otherHand.transform.GetComponent<ControllerScript>().climbingBackup = true;
  403. otherHand.transform.GetComponent<ControllerScript>().isClimbing = false;
  404. }
  405. isClimbing = true;
  406. ClimbVec = transform.position;
  407. ClimbVecHand = transform.Find("EmptyTransform").transform.position;
  408. ClimbQuat = transform.rotation;
  409. thePlayer.transform.GetComponent<Rigidbody>().useGravity = false;
  410. thePlayer.transform.GetComponent<Rigidbody>().velocity = Vector3.zero;
  411.  
  412. }
  413. if (SteamVR_Input._default.inActions.MenuPressed.GetStateUp(SteamVR_Input_Sources.RightHand) && !offHand)
  414. {
  415. if (otherHand.transform.GetComponent<ControllerScript>().climbingBackup == true)
  416. {
  417. otherHand.transform.GetComponent<ControllerScript>().isClimbing = true;
  418. //otherHand.transform.GetComponent<ControllerScript>().ClimbVec = otherHand.transform.position;
  419. //otherHand.transform.GetComponent<ControllerScript>().ClimbQuat = otherHand.transform.rotation;
  420. otherHand.transform.GetComponent<ControllerScript>().climbingBackup = false;
  421. }
  422. isClimbing = false;
  423. climbingBackup = false;
  424. thePlayer.transform.GetComponent<Rigidbody>().velocity = Vector3.zero;
  425. }
  426.  
  427. if (SteamVR_Input._default.inActions.MenuPressed.GetStateDown(SteamVR_Input_Sources.LeftHand) && isClimbing == false && offHand)
  428. {
  429. if (otherHand.transform.GetComponent<ControllerScript>().isClimbing == true)
  430. {
  431. otherHand.transform.GetComponent<ControllerScript>().climbingBackup = true;
  432. otherHand.transform.GetComponent<ControllerScript>().isClimbing = false;
  433. }
  434. isClimbing = true;
  435. ClimbVec = transform.position;
  436. ClimbVecHand = transform.Find("EmptyTransform").transform.position;
  437. ClimbQuat = transform.rotation;
  438. thePlayer.transform.GetComponent<Rigidbody>().useGravity = false;
  439. thePlayer.transform.GetComponent<Rigidbody>().velocity = Vector3.zero;
  440.  
  441. }
  442. if (SteamVR_Input._default.inActions.MenuPressed.GetStateUp(SteamVR_Input_Sources.LeftHand) && offHand)
  443. {
  444. if (otherHand.transform.GetComponent<ControllerScript>().climbingBackup == true)
  445. {
  446. otherHand.transform.GetComponent<ControllerScript>().isClimbing = true;
  447. //otherHand.transform.GetComponent<ControllerScript>().ClimbVec = otherHand.transform.position;
  448. //otherHand.transform.GetComponent<ControllerScript>().ClimbQuat = otherHand.transform.rotation;
  449. otherHand.transform.GetComponent<ControllerScript>().climbingBackup = false;
  450. }
  451. isClimbing = false;
  452. climbingBackup = false;
  453. thePlayer.transform.GetComponent<Rigidbody>().velocity = Vector3.zero;
  454. }
  455.  
  456. if (!isClimbing && !otherHand.transform.GetComponent<ControllerScript>().isClimbing)
  457. {
  458. thePlayer.transform.GetComponent<Rigidbody>().useGravity = true;
  459. }
  460.  
  461. ClimbingDistance = Vector3.Distance(ClimbVec, transform.position);
  462. if (ClimbingDistance > ClimbingMaxDistance)
  463. {
  464. climbingBackup = false;
  465. }
  466.  
  467.  
  468. /*
  469. if (otherHand.GetComponent<ControllerScript>().isClimbing == true && isClimbing == false && !offHand)
  470. {
  471. transform.Find("RightHand").transform.position = transform.Find("EmptyTransform").transform.position;
  472. transform.Find("RightHand").transform.position = transform.Find("EmptyTransform").transform.position;
  473. }
  474. if (otherHand.GetComponent<ControllerScript>().isClimbing == true && isClimbing == false && offHand)
  475. {
  476. transform.Find("LeftHand").transform.position = transform.Find("EmptyTransform").transform.position;
  477. transform.Find("LeftHand").transform.position = transform.Find("EmptyTransform").transform.position;
  478. }
  479. */
  480. /*
  481. if (otherHand.GetComponent<ControllerScript>().isClimbing == true && climbingBackup == false && !offHand)
  482. {
  483. transform.Find("RightHand").transform.position = transform.Find("EmptyTransform").transform.position;
  484. transform.Find("RightHand").transform.rotation = transform.Find("EmptyTransform").transform.rotation;
  485. }
  486. if (otherHand.GetComponent<ControllerScript>().isClimbing == true && climbingBackup == false && offHand)
  487. {
  488. transform.Find("LeftHand").transform.position = transform.Find("EmptyTransform").transform.position;
  489. transform.Find("LeftHand").transform.rotation = transform.Find("EmptyTransform").transform.rotation;
  490. }
  491. */
  492.  
  493. /*
  494. transform.Find("RightHand").transform.position = transform.Find("EmptyTransform").transform.position;
  495. transform.Find("RightHand").transform.rotation = transform.Find("EmptyTransform").transform.rotation;
  496.  
  497. */
  498.  
  499.  
  500. //thePlayer.transform.position += theRotater.transform.forward * Time.deltaTime * (touchpad.y * speed * sprint);
  501. if (isClimbing == false)
  502. {
  503. if (!flight)
  504. {
  505. if (touchpad.y > 0)
  506. {
  507. thePlayer.transform.position += new Vector3(transform.forward.x * Time.deltaTime * speed * playerHeight * sprint * touchpad.y, 0, transform.forward.z * Time.deltaTime * speed * playerHeight * sprint * touchpad.y);
  508. }
  509. else if (touchpad.y < 0)
  510. {
  511. thePlayer.transform.position -= new Vector3(transform.forward.x * Time.deltaTime * speed * playerHeight * sprint * -touchpad.y, 0, transform.forward.z * Time.deltaTime * speed * playerHeight * sprint * -touchpad.y);
  512. }
  513. if (touchpad.x > 0)
  514. {
  515. thePlayer.transform.position += new Vector3(transform.right.x * Time.deltaTime * speed * playerHeight * sprint * touchpad.x, 0, transform.right.z * Time.deltaTime * speed * playerHeight * sprint * touchpad.x);
  516. }
  517. else if (touchpad.x < 0)
  518. {
  519. thePlayer.transform.position -= new Vector3(transform.right.x * Time.deltaTime * speed * playerHeight * sprint * -touchpad.x, 0, transform.right.z * Time.deltaTime * speed * playerHeight * sprint * -touchpad.x);
  520. }
  521. }
  522. if (flight)
  523. {
  524. if (touchpad.y > 0)
  525. {
  526. thePlayer.transform.position += new Vector3(transform.forward.x * Time.deltaTime * speed * playerHeight * sprint * touchpad.y, transform.forward.y * Time.deltaTime * speed * playerHeight * sprint * touchpad.y, transform.forward.z * Time.deltaTime * speed * playerHeight * sprint * touchpad.y);
  527. }
  528. else if (touchpad.y < 0)
  529. {
  530. thePlayer.transform.position -= new Vector3(transform.forward.x * Time.deltaTime * speed * playerHeight * sprint * -touchpad.y, transform.forward.y * Time.deltaTime * speed * playerHeight * sprint * touchpad.y, transform.forward.z * Time.deltaTime * speed * playerHeight * sprint * -touchpad.y);
  531. }
  532. if (touchpad.x > 0)
  533. {
  534. thePlayer.transform.position += new Vector3(transform.right.x * Time.deltaTime * speed * playerHeight * sprint * touchpad.x, transform.right.x * Time.deltaTime * speed * playerHeight * sprint * touchpad.x, transform.right.z * Time.deltaTime * speed * playerHeight * sprint * touchpad.x);
  535. }
  536. else if (touchpad.x < 0)
  537. {
  538. thePlayer.transform.position -= new Vector3(transform.right.x * Time.deltaTime * speed * playerHeight * sprint * -touchpad.x, transform.right.z * Time.deltaTime * speed * playerHeight * sprint * -touchpad.x, transform.right.z * Time.deltaTime * speed * playerHeight * sprint * -touchpad.x);
  539. }
  540. }
  541. }
  542. else
  543. {
  544. //thePlayer.transform.position = ClimbVec + transform.localPosition;
  545.  
  546. Vector3 newPos = ClimbVec - transform.position;
  547. thePlayer.transform.position = thePlayer.transform.position + newPos;
  548. }
  549.  
  550.  
  551. //HOLD MAGAZINE
  552.  
  553. if (!offHand)
  554. {
  555. if (itemInHand != null && itemInHand.GetComponent<MagScript>() != null && itemInHand.GetComponent<MagScript>().isTaken == false)
  556. {
  557. itemInHand.transform.position = transform.position;
  558. itemInHand.transform.rotation = transform.rotation;
  559. }
  560. }
  561. if (offHand)
  562. {
  563. if (itemInHand != null && itemInHand.GetComponent<MagScript>() != null && itemInHand.GetComponent<MagScript>().isTaken == false)
  564. {
  565. itemInHand.transform.position = transform.position;
  566. itemInHand.transform.rotation = transform.rotation;
  567. }
  568. }
  569.  
  570. //HOLD RADIO
  571.  
  572. if (!offHand)
  573. {
  574. if (itemInHand != null && itemInHand.GetComponent<RadioScript>() != null && itemInHand.GetComponent<RadioScript>().isTaken == false)
  575. {
  576. Vector3 offset = itemInHand.GetComponent<RadioScript>().rightHandOffset;
  577. Vector3 POSoffset = itemInHand.GetComponent<RadioScript>().POSrightHandOffset;
  578. itemInHand.GetComponent<Rigidbody>().useGravity = false;
  579.  
  580. itemInHand.transform.position = transform.position;
  581. itemInHand.transform.position += transform.forward * POSoffset.x;
  582. itemInHand.transform.position += transform.up * POSoffset.y;
  583. itemInHand.transform.position += transform.right * POSoffset.z;
  584. itemInHand.transform.rotation = transform.rotation * Quaternion.Euler(offset.x, offset.y, offset.z);
  585.  
  586. if (SteamVR_Input._default.inActions.GripPressed.GetStateDown(SteamVR_Input_Sources.RightHand))
  587. {
  588. itemInHand.GetComponent<RadioScript>().active = true;
  589.  
  590. foreach (var myF in FindObjectsOfType<RadioScript>())
  591. {
  592. if (myF.dTotal == itemInHand.GetComponent<RadioScript>().dTotal)
  593. {
  594. myF.active = true;
  595. }
  596. }
  597. }
  598. else if (SteamVR_Input._default.inActions.GripPressed.GetLastStateUp(SteamVR_Input_Sources.RightHand))
  599. {
  600. itemInHand.GetComponent<RadioScript>().active = false;
  601.  
  602. foreach (var myF in FindObjectsOfType<RadioScript>())
  603. {
  604. if (myF.dTotal == itemInHand.GetComponent<RadioScript>().dTotal)
  605. {
  606. myF.active = false;
  607. }
  608. }
  609. }
  610. }
  611. }
  612. if (offHand)
  613. {
  614. if (itemInHand != null && itemInHand.GetComponent<RadioScript>() != null && itemInHand.GetComponent<RadioScript>().isTaken == false)
  615. {
  616. Vector3 offset = itemInHand.GetComponent<RadioScript>().leftHandOffest;
  617. Vector3 POSoffset = itemInHand.GetComponent<RadioScript>().POSleftHandOffest;
  618. itemInHand.GetComponent<Rigidbody>().useGravity = false;
  619.  
  620. itemInHand.transform.position = transform.position;
  621. itemInHand.transform.position += transform.forward * POSoffset.x;
  622. itemInHand.transform.position += transform.up * POSoffset.y;
  623. itemInHand.transform.position += transform.right * POSoffset.z;
  624. itemInHand.transform.rotation = transform.rotation * Quaternion.Euler(offset.x, offset.y, offset.z);
  625. }
  626. }
  627.  
  628. if (otherHand.GetComponent<ControllerScript>().itemInHand != null && otherHand.GetComponent<ControllerScript>().itemInHand.GetComponent<RadioScript>() != null)
  629. {
  630. if (itemInHand == null)
  631. {
  632. radioGuider.SetActive(true);
  633. RaycastHit hit;
  634. if (Physics.Raycast(transform.Find("InteractFinger").transform.position, transform.Find("InteractFinger").transform.TransformDirection(Vector3.forward), out hit))
  635. {
  636.  
  637.  
  638. if (hit.transform.GetComponent<RadioButton>() != null)
  639. {
  640. radioGuider.transform.position = hit.point;
  641. Debug.Log("HIT TARGET");
  642.  
  643.  
  644. if (SteamVR_Input._default.inActions.TriggerPressed.GetStateDown(SteamVR_Input_Sources.RightHand) && !offHand)
  645. {
  646. otherHand.transform.GetComponent<ControllerScript>().itemInHand.transform.GetComponent<RadioScript>().newDigit = hit.transform.GetComponent<RadioButton>().bID;
  647. }
  648.  
  649. }
  650. else
  651. {
  652. radioGuider.SetActive(false);
  653. }
  654.  
  655.  
  656. }
  657. }
  658. }
  659. else
  660. {
  661. radioGuider.SetActive(false);
  662. }
  663.  
  664.  
  665.  
  666.  
  667. ////////////HOLDING GUN
  668. if (!offHand) //RIGHT HANDED
  669. {
  670. if (itemInHand != null && itemInHand.GetComponent<GunProperties>() != null)
  671. {
  672. Vector3 GunScript = itemInHand.GetComponent<GunProperties>().rotationOffset;
  673.  
  674.  
  675.  
  676. itemInHand.transform.position = transform.position;
  677. itemInHand.transform.position -= itemInHand.transform.forward * itemInHand.GetComponent<GunProperties>().recoil;
  678.  
  679. transform.Find("RightHand").transform.position = itemInHand.transform.Find("triggerRight").transform.position;
  680. transform.Find("RightHand").transform.rotation = itemInHand.transform.Find("triggerRight").transform.rotation;
  681.  
  682. //TWO HANDED
  683. if (twoHanded)
  684. {
  685. itemInHand.transform.LookAt(otherHand.transform.position, (transform.forward + transform.up) + (transform.forward + transform.up));
  686. itemInHand.transform.Rotate(Vector3.right * -itemInHand.GetComponent<GunProperties>().recoilVertical, Space.Self);
  687. otherHand.transform.Find("LeftHand").transform.position = itemInHand.transform.Find("gripLeft").transform.position;
  688. otherHand.transform.Find("LeftHand").transform.rotation = itemInHand.transform.Find("gripLeft").transform.rotation;
  689. itemInHand.GetComponent<GunProperties>().useGrip = true;
  690. }
  691. //ONE HANDED
  692. else
  693. {
  694. //OFFHAND
  695. otherHand.transform.Find("LeftHand").transform.position = otherHand.transform.Find("EmptyTransform").transform.position;
  696. otherHand.transform.Find("LeftHand").transform.rotation = otherHand.transform.Find("EmptyTransform").transform.rotation;
  697.  
  698. itemInHand.transform.rotation = transform.rotation * Quaternion.Euler(GunScript.x - itemInHand.GetComponent<GunProperties>().recoilVertical, GunScript.y, GunScript.z);
  699. }
  700. }
  701. else
  702. {
  703. if (otherHand.GetComponent<ControllerScript>().itemInHand == null && !isClimbing && !climbingBackup)
  704. {
  705. transform.Find("RightHand").transform.position = transform.Find("EmptyTransform").transform.position;
  706. transform.Find("RightHand").transform.rotation = transform.Find("EmptyTransform").transform.rotation;
  707. }
  708. }
  709. }
  710. else //LEFT HANDED
  711. {
  712. if (itemInHand != null && itemInHand.GetComponent<GunProperties>() != null)
  713. {
  714. Vector3 GunScript = itemInHand.GetComponent<GunProperties>().rotationOffset;
  715.  
  716. itemInHand.transform.position = transform.position;
  717.  
  718. transform.Find("LeftHand").transform.position = itemInHand.transform.Find("triggerLeft").transform.position;
  719. transform.Find("LeftHand").transform.rotation = itemInHand.transform.Find("triggerLeft").transform.rotation;
  720.  
  721. //TWO HANDED
  722. if (twoHanded)
  723. {
  724. itemInHand.transform.LookAt(otherHand.transform.position, (transform.forward + transform.up) + (transform.forward + transform.up));
  725. itemInHand.transform.Rotate(Vector3.right * -itemInHand.GetComponent<GunProperties>().recoilVertical, Space.Self);
  726. otherHand.transform.Find("RightHand").transform.position = itemInHand.transform.Find("gripRight").transform.position;
  727. otherHand.transform.Find("RightHand").transform.rotation = itemInHand.transform.Find("gripRight").transform.rotation;
  728. itemInHand.GetComponent<GunProperties>().useGrip = true;
  729. }
  730. //ONE HANDED
  731. else
  732. {
  733. //OFFHAND
  734. otherHand.transform.Find("RightHand").transform.position = otherHand.transform.Find("EmptyTransform").transform.position;
  735. otherHand.transform.Find("RightHand").transform.rotation = otherHand.transform.Find("EmptyTransform").transform.rotation;
  736.  
  737. itemInHand.transform.rotation = transform.rotation * Quaternion.Euler(GunScript.x - itemInHand.GetComponent<GunProperties>().recoilVertical, GunScript.y, GunScript.z);
  738. }
  739. }
  740. else
  741. {
  742. if (otherHand.GetComponent<ControllerScript>().itemInHand == null && !isClimbing && !climbingBackup)
  743. {
  744. transform.Find("LeftHand").transform.position = transform.Find("EmptyTransform").transform.position;
  745. transform.Find("LeftHand").transform.rotation = transform.Find("EmptyTransform").transform.rotation;
  746. }
  747. }
  748. }
  749. }
  750. }
  751. private void LateUpdate()
  752. {
  753.  
  754. if (climbingBackup == true)
  755. {
  756. if (!offHand)
  757. {
  758. transform.Find("RightHand").transform.position = ClimbVecHand;
  759. transform.Find("RightHand").transform.rotation = ClimbQuat * transform.Find("EmptyTransform").transform.localRotation;
  760. }
  761. else
  762. {
  763. transform.Find("LeftHand").transform.position = ClimbVecHand;
  764. transform.Find("LeftHand").transform.rotation = ClimbQuat * transform.Find("EmptyTransform").transform.localRotation;
  765. }
  766.  
  767. isClimbing = false;
  768. }
  769.  
  770. if (isClimbing == true && !offHand)
  771. {
  772. transform.Find("RightHand").transform.position = ClimbVecHand;
  773. transform.Find("RightHand").transform.rotation = ClimbQuat * transform.Find("EmptyTransform").transform.localRotation;
  774. }
  775. if (isClimbing == true && offHand)
  776. {
  777.  
  778. transform.Find("LeftHand").transform.position = ClimbVecHand;
  779. transform.Find("LeftHand").transform.rotation = ClimbQuat * transform.Find("EmptyTransform").transform.localRotation;
  780. }
  781. }
  782.  
  783. private void OnTriggerStay(Collider Col)
  784. {
  785. if (photonView.isMine)
  786. {
  787. if (!offHand)
  788. {
  789. if (Col.gameObject.GetComponent<GunProperties>() != null && itemInHand == null)
  790. {
  791. if (SteamVR_Input._default.inActions.GripPressed.GetStateDown(SteamVR_Input_Sources.RightHand) && Col.gameObject.GetComponent<GunProperties>().isTaken == false && gripRelease == true)
  792. {
  793. Col.gameObject.GetComponent<GunProperties>().isTaken = true;
  794. if (itemInHand == null && weaponOnChest.GetComponent<WeaponOnChest>().currentWeaponOnChest != null)
  795. {
  796. weaponOnChest.GetComponent<WeaponOnChest>().currentWeaponOnChest = null;
  797. }
  798. itemInHand = Col.gameObject;
  799. itemInHand.GetComponent<BoxCollider>().enabled = false;
  800. itemInHand.GetComponent<PhotonView>().TransferOwnership(thePlayer.GetComponent<PhotonView>().ownerId);
  801. gripLevel = 0;
  802. otherHand.GetComponent<ControllerScript>().gripLevel = 1;
  803. }
  804. }
  805. }
  806. else
  807. {
  808. if (Col.gameObject.GetComponent<GunProperties>() != null && itemInHand == null)
  809. {
  810. if (SteamVR_Input._default.inActions.GripPressed.GetStateDown(SteamVR_Input_Sources.LeftHand) && Col.gameObject.GetComponent<GunProperties>().isTaken == false && gripRelease == true)
  811. {
  812. Col.gameObject.GetComponent<GunProperties>().isTaken = true;
  813. if (itemInHand == null && weaponOnChest.GetComponent<WeaponOnChest>().currentWeaponOnChest != null)
  814. {
  815. weaponOnChest.GetComponent<WeaponOnChest>().currentWeaponOnChest = null;
  816. }
  817. itemInHand = Col.gameObject;
  818. itemInHand.GetComponent<BoxCollider>().enabled = false;
  819. itemInHand.GetComponent<PhotonView>().TransferOwnership(thePlayer.GetComponent<PhotonView>().ownerId);
  820. gripLevel = 0;
  821. otherHand.GetComponent<ControllerScript>().gripLevel = 1;
  822. }
  823. }
  824. }
  825.  
  826. //GRIP MAG FROM MAG BAG
  827. if (SteamVR_Input._default.inActions.TriggerPressed.GetStateDown(SteamVR_Input_Sources.RightHand) && itemInHand == null && !offHand && Col.gameObject == magBag && thePlayer.GetComponent<PlayerScript>().mag1Amount > 0)
  828. {
  829. PhotonNetwork.Instantiate("Magazine01", transform.position, transform.rotation, 0);
  830. thePlayer.GetComponent<PlayerScript>().mag1Amount -= 1;
  831. }
  832. if (SteamVR_Input._default.inActions.TriggerPressed.GetStateDown(SteamVR_Input_Sources.LeftHand) && itemInHand == null && offHand && Col.gameObject == magBag && thePlayer.GetComponent<PlayerScript>().mag1Amount > 0)
  833. {
  834. PhotonNetwork.Instantiate("Magazine01", transform.position, transform.rotation, 0);
  835. thePlayer.GetComponent<PlayerScript>().mag1Amount -= 1;
  836. }
  837.  
  838.  
  839.  
  840. //GRIP MAGAZINE
  841.  
  842. if (SteamVR_Input._default.inActions.TriggerPressed.GetState(SteamVR_Input_Sources.RightHand) && itemInHand == null && !offHand && Col.gameObject.GetComponent<MagScript>() != null && Col.gameObject.GetComponent<MagScript>().isTaken == false)
  843. {
  844. itemInHand = Col.gameObject;
  845. itemInHand.transform.GetComponent<MeshCollider>().enabled = false;
  846. itemInHand.GetComponent<PhotonView>().TransferOwnership(thePlayer.GetComponent<PhotonView>().ownerId);
  847. gripLevel = 0;
  848. otherHand.GetComponent<ControllerScript>().gripLevel = 1;
  849. }
  850. if (SteamVR_Input._default.inActions.TriggerPressed.GetState(SteamVR_Input_Sources.LeftHand) && itemInHand == null && offHand && Col.gameObject.GetComponent<MagScript>() != null && Col.gameObject.GetComponent<MagScript>().isTaken == false)
  851. {
  852. itemInHand = Col.gameObject;
  853. itemInHand.transform.GetComponent<MeshCollider>().enabled = false;
  854. itemInHand.GetComponent<PhotonView>().TransferOwnership(thePlayer.GetComponent<PhotonView>().ownerId);
  855. gripLevel = 0;
  856. otherHand.GetComponent<ControllerScript>().gripLevel = 1;
  857. }
  858.  
  859. //GRIP RADIO
  860.  
  861. if (SteamVR_Input._default.inActions.TriggerPressed.GetState(SteamVR_Input_Sources.RightHand) && itemInHand == null && !offHand && Col.gameObject.GetComponent<RadioScript>() != null && Col.gameObject.GetComponent<RadioScript>().isTaken == false)
  862. {
  863. itemInHand = Col.gameObject;
  864. itemInHand.transform.GetComponent<BoxCollider>().enabled = false;
  865. itemInHand.GetComponent<PhotonView>().TransferOwnership(thePlayer.GetComponent<PhotonView>().ownerId);
  866. gripLevel = 0;
  867. otherHand.GetComponent<ControllerScript>().gripLevel = 1;
  868. }
  869. if (SteamVR_Input._default.inActions.TriggerPressed.GetState(SteamVR_Input_Sources.LeftHand) && itemInHand == null && offHand && Col.gameObject.GetComponent<RadioScript>() != null && Col.gameObject.GetComponent<RadioScript>().isTaken == false)
  870. {
  871. itemInHand = Col.gameObject;
  872. itemInHand.transform.GetComponent<BoxCollider>().enabled = false;
  873. itemInHand.GetComponent<PhotonView>().TransferOwnership(thePlayer.GetComponent<PhotonView>().ownerId);
  874. gripLevel = 0;
  875. otherHand.GetComponent<ControllerScript>().gripLevel = 1;
  876. }
  877.  
  878.  
  879. if (SteamVR_Input._default.inActions.TriggerPressed.GetState(SteamVR_Input_Sources.LeftHand) && offHand && Col.gameObject.name == "rifle bolt" && gripLevel >= 1)
  880. {
  881.  
  882. Debug.Log("BOLTMAN");
  883. gripLevel = 2;
  884. otherHand.GetComponent<ControllerScript>().gripLevel = 1;
  885.  
  886. GameObject boltParent = Col.transform.parent.transform.parent.transform.parent.gameObject;
  887. boltParent.GetComponent<GunProperties>().boltIsHolding = true;
  888. boltParent.GetComponent<GunProperties>().quickChamber = false;
  889. boltParent.GetComponent<GunProperties>().quickChamberRejected = true;
  890.  
  891. Debug.Log("HOLDING");
  892. itemInHand = Col.gameObject;
  893.  
  894. if (boltParent.GetComponent<GunProperties>().boltOffset > boltParent.GetComponent<GunProperties>().boltMaxDistance)
  895. {
  896. boltParent.GetComponent<GunProperties>().boltOffset = boltParent.GetComponent<GunProperties>().boltMaxDistance;
  897. }
  898. else if (boltParent.GetComponent<GunProperties>().boltOffset < 0)
  899. {
  900. boltParent.GetComponent<GunProperties>().boltOffset = 0;
  901. }
  902. else
  903. {
  904. boltParent.GetComponent<GunProperties>().boltOffset =
  905. (Vector3.Distance(Col.transform.parent.transform.Find("COCKING_DEFAULT").transform.position, transform.position) + Vector3.Distance(Col.transform.position, transform.position)) /
  906. boltParent.GetComponent<GunProperties>().boltDistanceBetweenTuner;
  907. }
  908. }
  909.  
  910. if (SteamVR_Input._default.inActions.TriggerPressed.GetState(SteamVR_Input_Sources.RightHand) && !offHand && Col.gameObject.name == "rifle bolt" && gripLevel >= 1)
  911. {
  912. gripLevel = 2;
  913. otherHand.GetComponent<ControllerScript>().gripLevel = 1;
  914.  
  915. GameObject boltParent = Col.transform.parent.transform.parent.transform.parent.gameObject;
  916. boltParent.GetComponent<GunProperties>().boltIsHolding = true;
  917. boltParent.GetComponent<GunProperties>().quickChamber = false;
  918. boltParent.GetComponent<GunProperties>().quickChamberRejected = true;
  919.  
  920. Debug.Log("CanYouSeeThis");
  921. itemInHand = Col.gameObject;
  922.  
  923. if (boltParent.GetComponent<GunProperties>().boltOffset > boltParent.GetComponent<GunProperties>().boltMaxDistance)
  924. {
  925. boltParent.GetComponent<GunProperties>().boltOffset = boltParent.GetComponent<GunProperties>().boltMaxDistance;
  926. }
  927. else if (boltParent.GetComponent<GunProperties>().boltOffset < 0)
  928. {
  929. boltParent.GetComponent<GunProperties>().boltOffset = 0;
  930. }
  931. else
  932. {
  933. boltParent.GetComponent<GunProperties>().boltOffset =
  934. (Vector3.Distance(Col.transform.parent.transform.Find("COCKING_DEFAULT").transform.position, transform.position) + Vector3.Distance(Col.transform.position, transform.position)) /
  935. boltParent.GetComponent<GunProperties>().boltDistanceBetweenTuner;
  936. }
  937. }
  938. }
  939. }
  940. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement