Gun script

This commit is contained in:
marcgauch committed 2023-12-07 19:24:27 +01:00
1 parent 1f0768bf43
commit a84b970db2
2 files changed
+60

No files matched your search

+49
View File
@@ -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<AudioSource>();
// 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();
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7f784a61b7cbfa864b26575436a02cc8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: