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(); } } }