Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using Valve.VR;
- public class ControllerScript : Photon.MonoBehaviour
- {
- public bool offHand;
- public SteamVR_Action_Vector2 _touchpadTouch;
- private float sprint = 1;
- public float sprintMultiplier = 2;
- public float speed = 5;
- private bool flight = false;
- public GameObject thePlayer;
- public GameObject otherHand;
- private bool twoHanded = false;
- public GameObject itemInHand;
- public Transform playerHead;
- private float playerHeight;
- public float heightSpeedMultiplier = 2f;
- public float heightPow;
- public float sittingHeight;
- public float maxHeight;
- public float gripDistance;
- private int gripLevel = 1;
- public GameObject radioGuider;
- //GRIP LEVEL 0: CANT USE BOLT
- //GRIP LEVEL 1: NEUTRAL: CAN GRAB ANYTHING
- //GRIP LEVEL 2: CAN ONLY MOVE BOLT
- private bool gripRelease = true;
- public bool isClimbing = false;
- public bool climbingBackup = false;
- public Vector3 ClimbVec;
- public Vector3 ClimbVecHand;
- public Quaternion ClimbQuat;
- public float ClimbingDistance;
- public float ClimbingMaxDistance;
- public GameObject magBag;
- public GameObject weaponOnChest;
- public float chestRadius;
- public Transform leftGripClimb;
- public Transform rightGripClimb;
- public GameObject handLerper;
- void Update()
- {
- if (photonView.isMine)
- {
- Vector2 touchpad = _touchpadTouch.GetAxis(SteamVR_Input_Sources.LeftHand);
- Vector2 useTouch = _touchpadTouch.GetAxis(SteamVR_Input_Sources.Any);
- if ((((thePlayer.transform.position.y + playerHead.position.y) / 2) + 1.5f) * Mathf.Pow(heightSpeedMultiplier, heightPow) < maxHeight)
- {
- playerHeight = (((thePlayer.transform.position.y + playerHead.position.y) / 2) + 1.5f) * Mathf.Pow(heightSpeedMultiplier, heightPow);
- }
- else
- {
- playerHeight = maxHeight + 0.1f;
- }
- //thePlayer.transform.position += Vector3.forward * Time.deltaTime * speed;
- //SPRINT TOGGLE
- //if (device.GetPressDown(touchpadButton))
- if (SteamVR_Input._default.inActions.TouchpadPressed.GetState(SteamVR_Input_Sources.LeftHand) && playerHeight > sittingHeight)
- {
- sprint = sprintMultiplier;
- }
- else
- {
- sprint = 1;
- }
- if (SteamVR_Input._default.inActions.TriggerPressed.GetStateUp(SteamVR_Input_Sources.LeftHand) && offHand && itemInHand != null)
- {
- if (itemInHand.name == "rifle bolt")
- {
- itemInHand.transform.parent.transform.parent.transform.parent.GetComponent<GunProperties>().boltIsHolding = false;
- gripLevel = 1;
- itemInHand = null;
- }
- }
- if (SteamVR_Input._default.inActions.TriggerPressed.GetStateUp(SteamVR_Input_Sources.RightHand) && !offHand && itemInHand != null)
- {
- if (itemInHand.name == "rifle bolt")
- {
- itemInHand.transform.parent.transform.parent.transform.parent.GetComponent<GunProperties>().boltIsHolding = false;
- gripLevel = 1;
- itemInHand = null;
- }
- }
- /*
- if (SteamVR_Input._default.inActions.TriggerPressed.GetState(SteamVR_Input_Sources.LeftHand))
- {
- flight = true;
- }
- else
- {
- flight = false;
- }
- */
- //MAG RELEASE FROM HAND
- if (SteamVR_Input._default.inActions.TriggerPressed.GetStateUp(SteamVR_Input_Sources.RightHand) && itemInHand != null && !offHand && itemInHand.GetComponent<MagScript>() != null)
- {
- itemInHand.transform.GetComponent<MeshCollider>().enabled = true;
- itemInHand.GetComponent<Rigidbody>().useGravity = true;
- itemInHand.GetComponent<Rigidbody>().velocity = Vector3.zero;
- itemInHand.GetComponent<Rigidbody>().AddForce((handLerper.transform.forward * handLerper.transform.GetComponent<HandLerper>().force) / itemInHand.GetComponent<MagScript>().weight);
- itemInHand = null;
- gripLevel = 1;
- otherHand.GetComponent<ControllerScript>().gripLevel = 1;
- }
- 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)
- {
- itemInHand.GetComponent<GunProperties>().magIn = false;
- itemInHand.GetComponent<GunProperties>().sound.PlayOneShot(itemInHand.GetComponent<GunProperties>().snd_mag_out, 1);
- }
- if (SteamVR_Input._default.inActions.TriggerPressed.GetStateUp(SteamVR_Input_Sources.LeftHand) && itemInHand != null && offHand && itemInHand.GetComponent<MagScript>() != null)
- {
- itemInHand.transform.GetComponent<MeshCollider>().enabled = true;
- itemInHand.GetComponent<Rigidbody>().useGravity = true;
- itemInHand.GetComponent<Rigidbody>().velocity = Vector3.zero;
- itemInHand.GetComponent<Rigidbody>().AddForce((handLerper.transform.forward * handLerper.transform.GetComponent<HandLerper>().force) / itemInHand.GetComponent<MagScript>().weight);
- itemInHand = null;
- gripLevel = 1;
- otherHand.GetComponent<ControllerScript>().gripLevel = 1;
- }
- 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)
- {
- itemInHand.GetComponent<GunProperties>().magIn = false;
- itemInHand.GetComponent<GunProperties>().sound.PlayOneShot(itemInHand.GetComponent<GunProperties>().snd_mag_out, 1);
- }
- //RADIO RELEASE FROM HAND
- if (SteamVR_Input._default.inActions.TriggerPressed.GetStateUp(SteamVR_Input_Sources.RightHand) && itemInHand != null && !offHand && itemInHand.GetComponent<RadioScript>() != null)
- {
- itemInHand.transform.GetComponent<RadioScript>().isTaken = false;
- itemInHand.transform.GetComponent<BoxCollider>().enabled = true;
- itemInHand.GetComponent<Rigidbody>().useGravity = true;
- itemInHand.GetComponent<Rigidbody>().velocity = Vector3.zero;
- itemInHand.GetComponent<Rigidbody>().AddForce((handLerper.transform.forward * handLerper.transform.GetComponent<HandLerper>().force) / itemInHand.GetComponent<RadioScript>().weight);
- itemInHand = null;
- gripLevel = 1;
- otherHand.GetComponent<ControllerScript>().gripLevel = 1;
- }
- if (SteamVR_Input._default.inActions.TriggerPressed.GetStateUp(SteamVR_Input_Sources.LeftHand) && itemInHand != null && offHand && itemInHand.GetComponent<RadioScript>() != null)
- {
- itemInHand.transform.GetComponent<RadioScript>().isTaken = false;
- itemInHand.transform.GetComponent<BoxCollider>().enabled = true;
- itemInHand.GetComponent<Rigidbody>().useGravity = true;
- itemInHand.GetComponent<Rigidbody>().velocity = Vector3.zero;
- itemInHand.GetComponent<Rigidbody>().AddForce((handLerper.transform.forward * handLerper.transform.GetComponent<HandLerper>().force) / itemInHand.GetComponent<RadioScript>().weight);
- itemInHand = null;
- gripLevel = 1;
- otherHand.GetComponent<ControllerScript>().gripLevel = 1;
- }
- if (SteamVR_Input._default.inActions.TouchpadPressed.GetStateDown(SteamVR_Input_Sources.RightHand) && itemInHand != null && !offHand && itemInHand.GetComponent<GunProperties>() != null && useTouch.y > 0)
- {
- itemInHand.GetComponent<GunProperties>().quickChamber = false;
- itemInHand.GetComponent<GunProperties>().quickChamberRejected = true;
- if (itemInHand.GetComponent<GunProperties>().ammo > 0)
- {
- itemInHand.GetComponent<GunProperties>().bulletInChamber = true;
- }
- }
- //MAG TO GUN
- /*
- if (itemInHand != null && offHand && itemInHand.GetComponent<GunProperties>() != null && otherHand.GetComponent<ControllerScript>().itemInHand != null && otherHand.GetComponent<ControllerScript>().itemInHand.GetComponent<MagScript>() != null)
- {
- Debug.Log("TESTING 1");
- if (Vector3.Distance(itemInHand.transform.Find("rifle1/rifle body/magazineTransform").transform.position, otherHand.transform.position) < 0.1f)
- {
- Debug.Log("TESTING 2");
- otherHand.GetComponent<MagScript>().parentGun = itemInHand;
- }
- }
- */
- if (SteamVR_Input._default.inActions.TriggerPressed.GetStateDown(SteamVR_Input_Sources.RightHand) && itemInHand != null && !offHand && itemInHand.GetComponent<GunProperties>() != null)
- {
- itemInHand.GetComponent<GunProperties>().isShooting = true;
- itemInHand.GetComponent<GunProperties>().trigger_click = true;
- }
- else
- {
- if (SteamVR_Input._default.inActions.TriggerPressed.GetStateUp(SteamVR_Input_Sources.RightHand) && itemInHand != null && !offHand && itemInHand.GetComponent<GunProperties>() != null)
- {
- itemInHand.GetComponent<GunProperties>().isShooting = false;
- itemInHand.GetComponent<GunProperties>().trigger_click = false;
- }
- }
- if (SteamVR_Input._default.inActions.TriggerPressed.GetStateDown(SteamVR_Input_Sources.LeftHand) && itemInHand != null && offHand && itemInHand.GetComponent<GunProperties>() != null)
- {
- itemInHand.GetComponent<GunProperties>().isShooting = true;
- itemInHand.GetComponent<GunProperties>().trigger_click = true;
- }
- else
- {
- if (SteamVR_Input._default.inActions.TriggerPressed.GetStateUp(SteamVR_Input_Sources.LeftHand) && itemInHand != null && offHand && itemInHand.GetComponent<GunProperties>() != null)
- {
- itemInHand.GetComponent<GunProperties>().isShooting = false;
- itemInHand.GetComponent<GunProperties>().trigger_click = false;
- }
- }
- //////////////////////GRIP
- if (SteamVR_Input._default.inActions.GripPressed.GetStateDown(SteamVR_Input_Sources.LeftHand))
- {
- if (itemInHand != null && itemInHand.GetComponent<GunProperties>() != null)
- {
- if (twoHanded)
- {
- twoHanded = false;
- itemInHand.GetComponent<GunProperties>().useGrip = false;
- }
- else
- {
- Debug.Log("GRIPPED");
- twoHanded = true;
- /*
- if (otherHand.GetComponent<ControllerScript>().itemInHand != null && Vector3.Distance(otherHand.GetComponent<ControllerScript>().itemInHand.transform.Find("gripLeft").transform.position, transform.position) < gripDistance)
- {
- Debug.Log("GRIPPED");
- twoHanded = true;
- }
- */
- }
- }
- }
- if (SteamVR_Input._default.inActions.GripPressed.GetStateDown(SteamVR_Input_Sources.RightHand))
- {
- if (itemInHand != null && itemInHand.GetComponent<GunProperties>() != null)
- {
- if (twoHanded)
- {
- twoHanded = false;
- itemInHand.GetComponent<GunProperties>().useGrip = false;
- }
- else
- {
- Debug.Log("GRIPPED");
- twoHanded = true;
- /*
- if (Vector3.Distance(itemInHand.transform.Find("gripRight").transform.position, transform.position) < gripDistance && otherHand.GetComponent<ControllerScript>().itemInHand != null)
- {
- twoHanded = true;
- }
- */
- }
- }
- }
- if (itemInHand != null && !offHand && itemInHand.GetComponent<GunProperties>() != null)
- {
- if (SteamVR_Input._default.inActions.GripPressed.GetStateDown(SteamVR_Input_Sources.RightHand))
- {
- if (Vector3.Distance(itemInHand.transform.position, weaponOnChest.transform.position) < chestRadius && weaponOnChest.GetComponent<WeaponOnChest>().currentWeaponOnChest == null)
- {
- itemInHand.transform.position = weaponOnChest.transform.position;
- itemInHand.transform.rotation = weaponOnChest.transform.rotation;
- weaponOnChest.GetComponent<WeaponOnChest>().currentWeaponOnChest = itemInHand;
- }
- else
- {
- itemInHand.transform.position = transform.position;
- itemInHand.transform.rotation = transform.rotation;
- weaponOnChest.GetComponent<WeaponOnChest>().currentWeaponOnChest = null;
- }
- gripRelease = false;
- twoHanded = false;
- itemInHand.GetComponent<Rigidbody>().useGravity = true;
- itemInHand.GetComponent<Rigidbody>().velocity = Vector3.zero;
- itemInHand.GetComponent<Rigidbody>().AddForce((handLerper.transform.forward * handLerper.transform.GetComponent<HandLerper>().force) / itemInHand.GetComponent<GunProperties>().weight);
- itemInHand.GetComponent<BoxCollider>().enabled = true;
- itemInHand.GetComponent<GunProperties>().isShooting = false;
- itemInHand.GetComponent<GunProperties>().useGrip = false;
- itemInHand.GetComponent<GunProperties>().isTaken = false;
- itemInHand.GetComponent<GunProperties>().trigger_click = false;
- itemInHand = null;
- if (!isClimbing && !climbingBackup)
- {
- otherHand.transform.Find("LeftHand").transform.position = otherHand.transform.Find("EmptyTransform").transform.position;
- otherHand.transform.Find("LeftHand").transform.rotation = otherHand.transform.Find("EmptyTransform").transform.rotation;
- transform.Find("RightHand").transform.position = transform.Find("EmptyTransform").transform.position;
- transform.Find("RightHand").transform.rotation = transform.Find("EmptyTransform").transform.rotation;
- }
- }
- }
- if (itemInHand != null && offHand && itemInHand.GetComponent<GunProperties>() != null)
- {
- if (SteamVR_Input._default.inActions.GripPressed.GetStateDown(SteamVR_Input_Sources.LeftHand))
- {
- if (Vector3.Distance(itemInHand.transform.position, weaponOnChest.transform.position) < chestRadius && weaponOnChest.GetComponent<WeaponOnChest>().currentWeaponOnChest == null)
- {
- itemInHand.transform.position = weaponOnChest.transform.position;
- itemInHand.transform.rotation = weaponOnChest.transform.rotation;
- weaponOnChest.GetComponent<WeaponOnChest>().currentWeaponOnChest = itemInHand;
- }
- else
- {
- itemInHand.transform.position = transform.position;
- itemInHand.transform.rotation = transform.rotation;
- weaponOnChest.GetComponent<WeaponOnChest>().currentWeaponOnChest = null;
- }
- gripRelease = false;
- twoHanded = false;
- itemInHand.GetComponent<Rigidbody>().useGravity = true;
- itemInHand.GetComponent<Rigidbody>().velocity = Vector3.zero;
- itemInHand.GetComponent<Rigidbody>().AddForce((handLerper.transform.forward * handLerper.transform.GetComponent<HandLerper>().force) / itemInHand.GetComponent<GunProperties>().weight);
- itemInHand.GetComponent<BoxCollider>().enabled = true;
- itemInHand.GetComponent<GunProperties>().isShooting = false;
- itemInHand.GetComponent<GunProperties>().useGrip = false;
- itemInHand.GetComponent<GunProperties>().isTaken = false;
- itemInHand.GetComponent<GunProperties>().trigger_click = false;
- itemInHand = null;
- if (!isClimbing && !climbingBackup)
- {
- transform.Find("LeftHand").transform.position = transform.Find("EmptyTransform").transform.position;
- transform.Find("LeftHand").transform.rotation = transform.Find("EmptyTransform").transform.rotation;
- otherHand.transform.Find("RightHand").transform.position = otherHand.transform.Find("EmptyTransform").transform.position;
- otherHand.transform.Find("RightHand").transform.rotation = otherHand.transform.Find("EmptyTransform").transform.rotation;
- }
- }
- }
- if (SteamVR_Input._default.inActions.GripPressed.GetStateUp(SteamVR_Input_Sources.LeftHand) && offHand)
- {
- gripRelease = true;
- }
- if (SteamVR_Input._default.inActions.GripPressed.GetStateUp(SteamVR_Input_Sources.RightHand) && !offHand)
- {
- gripRelease = true;
- }
- //CLIMBING
- if (SteamVR_Input._default.inActions.MenuPressed.GetStateDown(SteamVR_Input_Sources.RightHand) && isClimbing == false && !offHand)
- {
- if (otherHand.transform.GetComponent<ControllerScript>().isClimbing == true)
- {
- otherHand.transform.GetComponent<ControllerScript>().climbingBackup = true;
- otherHand.transform.GetComponent<ControllerScript>().isClimbing = false;
- }
- isClimbing = true;
- ClimbVec = transform.position;
- ClimbVecHand = transform.Find("EmptyTransform").transform.position;
- ClimbQuat = transform.rotation;
- thePlayer.transform.GetComponent<Rigidbody>().useGravity = false;
- thePlayer.transform.GetComponent<Rigidbody>().velocity = Vector3.zero;
- }
- if (SteamVR_Input._default.inActions.MenuPressed.GetStateUp(SteamVR_Input_Sources.RightHand) && !offHand)
- {
- if (otherHand.transform.GetComponent<ControllerScript>().climbingBackup == true)
- {
- otherHand.transform.GetComponent<ControllerScript>().isClimbing = true;
- //otherHand.transform.GetComponent<ControllerScript>().ClimbVec = otherHand.transform.position;
- //otherHand.transform.GetComponent<ControllerScript>().ClimbQuat = otherHand.transform.rotation;
- otherHand.transform.GetComponent<ControllerScript>().climbingBackup = false;
- }
- isClimbing = false;
- climbingBackup = false;
- thePlayer.transform.GetComponent<Rigidbody>().velocity = Vector3.zero;
- }
- if (SteamVR_Input._default.inActions.MenuPressed.GetStateDown(SteamVR_Input_Sources.LeftHand) && isClimbing == false && offHand)
- {
- if (otherHand.transform.GetComponent<ControllerScript>().isClimbing == true)
- {
- otherHand.transform.GetComponent<ControllerScript>().climbingBackup = true;
- otherHand.transform.GetComponent<ControllerScript>().isClimbing = false;
- }
- isClimbing = true;
- ClimbVec = transform.position;
- ClimbVecHand = transform.Find("EmptyTransform").transform.position;
- ClimbQuat = transform.rotation;
- thePlayer.transform.GetComponent<Rigidbody>().useGravity = false;
- thePlayer.transform.GetComponent<Rigidbody>().velocity = Vector3.zero;
- }
- if (SteamVR_Input._default.inActions.MenuPressed.GetStateUp(SteamVR_Input_Sources.LeftHand) && offHand)
- {
- if (otherHand.transform.GetComponent<ControllerScript>().climbingBackup == true)
- {
- otherHand.transform.GetComponent<ControllerScript>().isClimbing = true;
- //otherHand.transform.GetComponent<ControllerScript>().ClimbVec = otherHand.transform.position;
- //otherHand.transform.GetComponent<ControllerScript>().ClimbQuat = otherHand.transform.rotation;
- otherHand.transform.GetComponent<ControllerScript>().climbingBackup = false;
- }
- isClimbing = false;
- climbingBackup = false;
- thePlayer.transform.GetComponent<Rigidbody>().velocity = Vector3.zero;
- }
- if (!isClimbing && !otherHand.transform.GetComponent<ControllerScript>().isClimbing)
- {
- thePlayer.transform.GetComponent<Rigidbody>().useGravity = true;
- }
- ClimbingDistance = Vector3.Distance(ClimbVec, transform.position);
- if (ClimbingDistance > ClimbingMaxDistance)
- {
- climbingBackup = false;
- }
- /*
- if (otherHand.GetComponent<ControllerScript>().isClimbing == true && isClimbing == false && !offHand)
- {
- transform.Find("RightHand").transform.position = transform.Find("EmptyTransform").transform.position;
- transform.Find("RightHand").transform.position = transform.Find("EmptyTransform").transform.position;
- }
- if (otherHand.GetComponent<ControllerScript>().isClimbing == true && isClimbing == false && offHand)
- {
- transform.Find("LeftHand").transform.position = transform.Find("EmptyTransform").transform.position;
- transform.Find("LeftHand").transform.position = transform.Find("EmptyTransform").transform.position;
- }
- */
- /*
- if (otherHand.GetComponent<ControllerScript>().isClimbing == true && climbingBackup == false && !offHand)
- {
- transform.Find("RightHand").transform.position = transform.Find("EmptyTransform").transform.position;
- transform.Find("RightHand").transform.rotation = transform.Find("EmptyTransform").transform.rotation;
- }
- if (otherHand.GetComponent<ControllerScript>().isClimbing == true && climbingBackup == false && offHand)
- {
- transform.Find("LeftHand").transform.position = transform.Find("EmptyTransform").transform.position;
- transform.Find("LeftHand").transform.rotation = transform.Find("EmptyTransform").transform.rotation;
- }
- */
- /*
- transform.Find("RightHand").transform.position = transform.Find("EmptyTransform").transform.position;
- transform.Find("RightHand").transform.rotation = transform.Find("EmptyTransform").transform.rotation;
- */
- //thePlayer.transform.position += theRotater.transform.forward * Time.deltaTime * (touchpad.y * speed * sprint);
- if (isClimbing == false)
- {
- if (!flight)
- {
- if (touchpad.y > 0)
- {
- 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);
- }
- else if (touchpad.y < 0)
- {
- 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);
- }
- if (touchpad.x > 0)
- {
- 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);
- }
- else if (touchpad.x < 0)
- {
- 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);
- }
- }
- if (flight)
- {
- if (touchpad.y > 0)
- {
- 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);
- }
- else if (touchpad.y < 0)
- {
- 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);
- }
- if (touchpad.x > 0)
- {
- 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);
- }
- else if (touchpad.x < 0)
- {
- 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);
- }
- }
- }
- else
- {
- //thePlayer.transform.position = ClimbVec + transform.localPosition;
- Vector3 newPos = ClimbVec - transform.position;
- thePlayer.transform.position = thePlayer.transform.position + newPos;
- }
- //HOLD MAGAZINE
- if (!offHand)
- {
- if (itemInHand != null && itemInHand.GetComponent<MagScript>() != null && itemInHand.GetComponent<MagScript>().isTaken == false)
- {
- itemInHand.transform.position = transform.position;
- itemInHand.transform.rotation = transform.rotation;
- }
- }
- if (offHand)
- {
- if (itemInHand != null && itemInHand.GetComponent<MagScript>() != null && itemInHand.GetComponent<MagScript>().isTaken == false)
- {
- itemInHand.transform.position = transform.position;
- itemInHand.transform.rotation = transform.rotation;
- }
- }
- //HOLD RADIO
- if (!offHand)
- {
- if (itemInHand != null && itemInHand.GetComponent<RadioScript>() != null && itemInHand.GetComponent<RadioScript>().isTaken == false)
- {
- Vector3 offset = itemInHand.GetComponent<RadioScript>().rightHandOffset;
- Vector3 POSoffset = itemInHand.GetComponent<RadioScript>().POSrightHandOffset;
- itemInHand.GetComponent<Rigidbody>().useGravity = false;
- itemInHand.transform.position = transform.position;
- itemInHand.transform.position += transform.forward * POSoffset.x;
- itemInHand.transform.position += transform.up * POSoffset.y;
- itemInHand.transform.position += transform.right * POSoffset.z;
- itemInHand.transform.rotation = transform.rotation * Quaternion.Euler(offset.x, offset.y, offset.z);
- if (SteamVR_Input._default.inActions.GripPressed.GetStateDown(SteamVR_Input_Sources.RightHand))
- {
- itemInHand.GetComponent<RadioScript>().active = true;
- foreach (var myF in FindObjectsOfType<RadioScript>())
- {
- if (myF.dTotal == itemInHand.GetComponent<RadioScript>().dTotal)
- {
- myF.active = true;
- }
- }
- }
- else if (SteamVR_Input._default.inActions.GripPressed.GetLastStateUp(SteamVR_Input_Sources.RightHand))
- {
- itemInHand.GetComponent<RadioScript>().active = false;
- foreach (var myF in FindObjectsOfType<RadioScript>())
- {
- if (myF.dTotal == itemInHand.GetComponent<RadioScript>().dTotal)
- {
- myF.active = false;
- }
- }
- }
- }
- }
- if (offHand)
- {
- if (itemInHand != null && itemInHand.GetComponent<RadioScript>() != null && itemInHand.GetComponent<RadioScript>().isTaken == false)
- {
- Vector3 offset = itemInHand.GetComponent<RadioScript>().leftHandOffest;
- Vector3 POSoffset = itemInHand.GetComponent<RadioScript>().POSleftHandOffest;
- itemInHand.GetComponent<Rigidbody>().useGravity = false;
- itemInHand.transform.position = transform.position;
- itemInHand.transform.position += transform.forward * POSoffset.x;
- itemInHand.transform.position += transform.up * POSoffset.y;
- itemInHand.transform.position += transform.right * POSoffset.z;
- itemInHand.transform.rotation = transform.rotation * Quaternion.Euler(offset.x, offset.y, offset.z);
- }
- }
- if (otherHand.GetComponent<ControllerScript>().itemInHand != null && otherHand.GetComponent<ControllerScript>().itemInHand.GetComponent<RadioScript>() != null)
- {
- if (itemInHand == null)
- {
- radioGuider.SetActive(true);
- RaycastHit hit;
- if (Physics.Raycast(transform.Find("InteractFinger").transform.position, transform.Find("InteractFinger").transform.TransformDirection(Vector3.forward), out hit))
- {
- if (hit.transform.GetComponent<RadioButton>() != null)
- {
- radioGuider.transform.position = hit.point;
- Debug.Log("HIT TARGET");
- if (SteamVR_Input._default.inActions.TriggerPressed.GetStateDown(SteamVR_Input_Sources.RightHand) && !offHand)
- {
- otherHand.transform.GetComponent<ControllerScript>().itemInHand.transform.GetComponent<RadioScript>().newDigit = hit.transform.GetComponent<RadioButton>().bID;
- }
- }
- else
- {
- radioGuider.SetActive(false);
- }
- }
- }
- }
- else
- {
- radioGuider.SetActive(false);
- }
- ////////////HOLDING GUN
- if (!offHand) //RIGHT HANDED
- {
- if (itemInHand != null && itemInHand.GetComponent<GunProperties>() != null)
- {
- Vector3 GunScript = itemInHand.GetComponent<GunProperties>().rotationOffset;
- itemInHand.transform.position = transform.position;
- itemInHand.transform.position -= itemInHand.transform.forward * itemInHand.GetComponent<GunProperties>().recoil;
- transform.Find("RightHand").transform.position = itemInHand.transform.Find("triggerRight").transform.position;
- transform.Find("RightHand").transform.rotation = itemInHand.transform.Find("triggerRight").transform.rotation;
- //TWO HANDED
- if (twoHanded)
- {
- itemInHand.transform.LookAt(otherHand.transform.position, (transform.forward + transform.up) + (transform.forward + transform.up));
- itemInHand.transform.Rotate(Vector3.right * -itemInHand.GetComponent<GunProperties>().recoilVertical, Space.Self);
- otherHand.transform.Find("LeftHand").transform.position = itemInHand.transform.Find("gripLeft").transform.position;
- otherHand.transform.Find("LeftHand").transform.rotation = itemInHand.transform.Find("gripLeft").transform.rotation;
- itemInHand.GetComponent<GunProperties>().useGrip = true;
- }
- //ONE HANDED
- else
- {
- //OFFHAND
- otherHand.transform.Find("LeftHand").transform.position = otherHand.transform.Find("EmptyTransform").transform.position;
- otherHand.transform.Find("LeftHand").transform.rotation = otherHand.transform.Find("EmptyTransform").transform.rotation;
- itemInHand.transform.rotation = transform.rotation * Quaternion.Euler(GunScript.x - itemInHand.GetComponent<GunProperties>().recoilVertical, GunScript.y, GunScript.z);
- }
- }
- else
- {
- if (otherHand.GetComponent<ControllerScript>().itemInHand == null && !isClimbing && !climbingBackup)
- {
- transform.Find("RightHand").transform.position = transform.Find("EmptyTransform").transform.position;
- transform.Find("RightHand").transform.rotation = transform.Find("EmptyTransform").transform.rotation;
- }
- }
- }
- else //LEFT HANDED
- {
- if (itemInHand != null && itemInHand.GetComponent<GunProperties>() != null)
- {
- Vector3 GunScript = itemInHand.GetComponent<GunProperties>().rotationOffset;
- itemInHand.transform.position = transform.position;
- transform.Find("LeftHand").transform.position = itemInHand.transform.Find("triggerLeft").transform.position;
- transform.Find("LeftHand").transform.rotation = itemInHand.transform.Find("triggerLeft").transform.rotation;
- //TWO HANDED
- if (twoHanded)
- {
- itemInHand.transform.LookAt(otherHand.transform.position, (transform.forward + transform.up) + (transform.forward + transform.up));
- itemInHand.transform.Rotate(Vector3.right * -itemInHand.GetComponent<GunProperties>().recoilVertical, Space.Self);
- otherHand.transform.Find("RightHand").transform.position = itemInHand.transform.Find("gripRight").transform.position;
- otherHand.transform.Find("RightHand").transform.rotation = itemInHand.transform.Find("gripRight").transform.rotation;
- itemInHand.GetComponent<GunProperties>().useGrip = true;
- }
- //ONE HANDED
- else
- {
- //OFFHAND
- otherHand.transform.Find("RightHand").transform.position = otherHand.transform.Find("EmptyTransform").transform.position;
- otherHand.transform.Find("RightHand").transform.rotation = otherHand.transform.Find("EmptyTransform").transform.rotation;
- itemInHand.transform.rotation = transform.rotation * Quaternion.Euler(GunScript.x - itemInHand.GetComponent<GunProperties>().recoilVertical, GunScript.y, GunScript.z);
- }
- }
- else
- {
- if (otherHand.GetComponent<ControllerScript>().itemInHand == null && !isClimbing && !climbingBackup)
- {
- transform.Find("LeftHand").transform.position = transform.Find("EmptyTransform").transform.position;
- transform.Find("LeftHand").transform.rotation = transform.Find("EmptyTransform").transform.rotation;
- }
- }
- }
- }
- }
- private void LateUpdate()
- {
- if (climbingBackup == true)
- {
- if (!offHand)
- {
- transform.Find("RightHand").transform.position = ClimbVecHand;
- transform.Find("RightHand").transform.rotation = ClimbQuat * transform.Find("EmptyTransform").transform.localRotation;
- }
- else
- {
- transform.Find("LeftHand").transform.position = ClimbVecHand;
- transform.Find("LeftHand").transform.rotation = ClimbQuat * transform.Find("EmptyTransform").transform.localRotation;
- }
- isClimbing = false;
- }
- if (isClimbing == true && !offHand)
- {
- transform.Find("RightHand").transform.position = ClimbVecHand;
- transform.Find("RightHand").transform.rotation = ClimbQuat * transform.Find("EmptyTransform").transform.localRotation;
- }
- if (isClimbing == true && offHand)
- {
- transform.Find("LeftHand").transform.position = ClimbVecHand;
- transform.Find("LeftHand").transform.rotation = ClimbQuat * transform.Find("EmptyTransform").transform.localRotation;
- }
- }
- private void OnTriggerStay(Collider Col)
- {
- if (photonView.isMine)
- {
- if (!offHand)
- {
- if (Col.gameObject.GetComponent<GunProperties>() != null && itemInHand == null)
- {
- if (SteamVR_Input._default.inActions.GripPressed.GetStateDown(SteamVR_Input_Sources.RightHand) && Col.gameObject.GetComponent<GunProperties>().isTaken == false && gripRelease == true)
- {
- Col.gameObject.GetComponent<GunProperties>().isTaken = true;
- if (itemInHand == null && weaponOnChest.GetComponent<WeaponOnChest>().currentWeaponOnChest != null)
- {
- weaponOnChest.GetComponent<WeaponOnChest>().currentWeaponOnChest = null;
- }
- itemInHand = Col.gameObject;
- itemInHand.GetComponent<BoxCollider>().enabled = false;
- itemInHand.GetComponent<PhotonView>().TransferOwnership(thePlayer.GetComponent<PhotonView>().ownerId);
- gripLevel = 0;
- otherHand.GetComponent<ControllerScript>().gripLevel = 1;
- }
- }
- }
- else
- {
- if (Col.gameObject.GetComponent<GunProperties>() != null && itemInHand == null)
- {
- if (SteamVR_Input._default.inActions.GripPressed.GetStateDown(SteamVR_Input_Sources.LeftHand) && Col.gameObject.GetComponent<GunProperties>().isTaken == false && gripRelease == true)
- {
- Col.gameObject.GetComponent<GunProperties>().isTaken = true;
- if (itemInHand == null && weaponOnChest.GetComponent<WeaponOnChest>().currentWeaponOnChest != null)
- {
- weaponOnChest.GetComponent<WeaponOnChest>().currentWeaponOnChest = null;
- }
- itemInHand = Col.gameObject;
- itemInHand.GetComponent<BoxCollider>().enabled = false;
- itemInHand.GetComponent<PhotonView>().TransferOwnership(thePlayer.GetComponent<PhotonView>().ownerId);
- gripLevel = 0;
- otherHand.GetComponent<ControllerScript>().gripLevel = 1;
- }
- }
- }
- //GRIP MAG FROM MAG BAG
- if (SteamVR_Input._default.inActions.TriggerPressed.GetStateDown(SteamVR_Input_Sources.RightHand) && itemInHand == null && !offHand && Col.gameObject == magBag && thePlayer.GetComponent<PlayerScript>().mag1Amount > 0)
- {
- PhotonNetwork.Instantiate("Magazine01", transform.position, transform.rotation, 0);
- thePlayer.GetComponent<PlayerScript>().mag1Amount -= 1;
- }
- if (SteamVR_Input._default.inActions.TriggerPressed.GetStateDown(SteamVR_Input_Sources.LeftHand) && itemInHand == null && offHand && Col.gameObject == magBag && thePlayer.GetComponent<PlayerScript>().mag1Amount > 0)
- {
- PhotonNetwork.Instantiate("Magazine01", transform.position, transform.rotation, 0);
- thePlayer.GetComponent<PlayerScript>().mag1Amount -= 1;
- }
- //GRIP MAGAZINE
- 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)
- {
- itemInHand = Col.gameObject;
- itemInHand.transform.GetComponent<MeshCollider>().enabled = false;
- itemInHand.GetComponent<PhotonView>().TransferOwnership(thePlayer.GetComponent<PhotonView>().ownerId);
- gripLevel = 0;
- otherHand.GetComponent<ControllerScript>().gripLevel = 1;
- }
- 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)
- {
- itemInHand = Col.gameObject;
- itemInHand.transform.GetComponent<MeshCollider>().enabled = false;
- itemInHand.GetComponent<PhotonView>().TransferOwnership(thePlayer.GetComponent<PhotonView>().ownerId);
- gripLevel = 0;
- otherHand.GetComponent<ControllerScript>().gripLevel = 1;
- }
- //GRIP RADIO
- 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)
- {
- itemInHand = Col.gameObject;
- itemInHand.transform.GetComponent<BoxCollider>().enabled = false;
- itemInHand.GetComponent<PhotonView>().TransferOwnership(thePlayer.GetComponent<PhotonView>().ownerId);
- gripLevel = 0;
- otherHand.GetComponent<ControllerScript>().gripLevel = 1;
- }
- 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)
- {
- itemInHand = Col.gameObject;
- itemInHand.transform.GetComponent<BoxCollider>().enabled = false;
- itemInHand.GetComponent<PhotonView>().TransferOwnership(thePlayer.GetComponent<PhotonView>().ownerId);
- gripLevel = 0;
- otherHand.GetComponent<ControllerScript>().gripLevel = 1;
- }
- if (SteamVR_Input._default.inActions.TriggerPressed.GetState(SteamVR_Input_Sources.LeftHand) && offHand && Col.gameObject.name == "rifle bolt" && gripLevel >= 1)
- {
- Debug.Log("BOLTMAN");
- gripLevel = 2;
- otherHand.GetComponent<ControllerScript>().gripLevel = 1;
- GameObject boltParent = Col.transform.parent.transform.parent.transform.parent.gameObject;
- boltParent.GetComponent<GunProperties>().boltIsHolding = true;
- boltParent.GetComponent<GunProperties>().quickChamber = false;
- boltParent.GetComponent<GunProperties>().quickChamberRejected = true;
- Debug.Log("HOLDING");
- itemInHand = Col.gameObject;
- if (boltParent.GetComponent<GunProperties>().boltOffset > boltParent.GetComponent<GunProperties>().boltMaxDistance)
- {
- boltParent.GetComponent<GunProperties>().boltOffset = boltParent.GetComponent<GunProperties>().boltMaxDistance;
- }
- else if (boltParent.GetComponent<GunProperties>().boltOffset < 0)
- {
- boltParent.GetComponent<GunProperties>().boltOffset = 0;
- }
- else
- {
- boltParent.GetComponent<GunProperties>().boltOffset =
- (Vector3.Distance(Col.transform.parent.transform.Find("COCKING_DEFAULT").transform.position, transform.position) + Vector3.Distance(Col.transform.position, transform.position)) /
- boltParent.GetComponent<GunProperties>().boltDistanceBetweenTuner;
- }
- }
- if (SteamVR_Input._default.inActions.TriggerPressed.GetState(SteamVR_Input_Sources.RightHand) && !offHand && Col.gameObject.name == "rifle bolt" && gripLevel >= 1)
- {
- gripLevel = 2;
- otherHand.GetComponent<ControllerScript>().gripLevel = 1;
- GameObject boltParent = Col.transform.parent.transform.parent.transform.parent.gameObject;
- boltParent.GetComponent<GunProperties>().boltIsHolding = true;
- boltParent.GetComponent<GunProperties>().quickChamber = false;
- boltParent.GetComponent<GunProperties>().quickChamberRejected = true;
- Debug.Log("CanYouSeeThis");
- itemInHand = Col.gameObject;
- if (boltParent.GetComponent<GunProperties>().boltOffset > boltParent.GetComponent<GunProperties>().boltMaxDistance)
- {
- boltParent.GetComponent<GunProperties>().boltOffset = boltParent.GetComponent<GunProperties>().boltMaxDistance;
- }
- else if (boltParent.GetComponent<GunProperties>().boltOffset < 0)
- {
- boltParent.GetComponent<GunProperties>().boltOffset = 0;
- }
- else
- {
- boltParent.GetComponent<GunProperties>().boltOffset =
- (Vector3.Distance(Col.transform.parent.transform.Find("COCKING_DEFAULT").transform.position, transform.position) + Vector3.Distance(Col.transform.position, transform.position)) /
- boltParent.GetComponent<GunProperties>().boltDistanceBetweenTuner;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement