From a84b970db2e21a14129c833841bc6ce222b69436 Mon Sep 17 00:00:00 2001 From: marcgauch <34353267+marcgauch@users.noreply.github.com> Date: Thu, 7 Dec 2023 19:24:27 +0100 Subject: [PATCH] Gun script --- Assets/iamagun.cs | 49 ++++++++++++++++++++++++++++++++++++++++++ Assets/iamagun.cs.meta | 11 ++++++++++ 2 files changed, 60 insertions(+) create mode 100644 Assets/iamagun.cs create mode 100644 Assets/iamagun.cs.meta diff --git a/Assets/iamagun.cs b/Assets/iamagun.cs new file mode 100644 index 0000000..06b23a3 --- /dev/null +++ b/Assets/iamagun.cs @@ -0,0 +1,49 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class iamagun : MonoBehaviour + +{ + + public SimpleShoot simpleShoot; + public OVRInput.Button shootButton; + + public Transform offset; + private AudioSource audio; + + private Vector3 offsetPosition; + + // Start is called before the first frame update + void Start() + { + audio = GetComponent(); + + // Pre-calculate the offset position based on the offset transform + offsetPosition = offset.position; + } + + // Update is called once per frame + void Update() + { + if (OVRInput.IsControllerConnected(OVRInput.Controller.RTouch)) + { + // Get the local position and rotation of the controller + Vector3 controllerLocalPosition = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch); + Quaternion controllerLocalRotation = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch); + + // Apply the pre-calculated offset position to the local position + Vector3 finalPosition = controllerLocalPosition + controllerLocalRotation * offsetPosition; + transform.position = finalPosition; + + // Set the cube's rotation to match the controller's rotation + transform.rotation = controllerLocalRotation; + } + + if (OVRInput.GetDown(shootButton)) + { + simpleShoot.StartShoot(); + audio.Play(); + } + } +} diff --git a/Assets/iamagun.cs.meta b/Assets/iamagun.cs.meta new file mode 100644 index 0000000..9636f0c --- /dev/null +++ b/Assets/iamagun.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7f784a61b7cbfa864b26575436a02cc8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: