| | | 1 | | using System.Collections; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using UnityEngine; |
| | | 4 | | using UnityEngine.XR.Interaction.Toolkit; |
| | | 5 | | |
| | | 6 | | public class LaunchObjects : MonoBehaviour |
| | | 7 | | { |
| | 64 | 8 | | public float launchForce = 5.0f; |
| | | 9 | | |
| | | 10 | | [Header("Audio")] |
| | | 11 | | public AudioClip audioClip; |
| | | 12 | | public AudioSource audioSource; |
| | | 13 | | |
| | | 14 | | public void OnSelectExit(XRBaseInteractor interactor) |
| | 1 | 15 | | { |
| | 1 | 16 | | Rigidbody rb = GetComponent<Rigidbody>(); |
| | 1 | 17 | | if (rb != null) |
| | 1 | 18 | | { |
| | 1 | 19 | | Vector3 launchDirection = interactor.transform.forward; |
| | 1 | 20 | | rb.AddForce(launchDirection * launchForce, ForceMode.Impulse); |
| | 1 | 21 | | } |
| | 1 | 22 | | } |
| | | 23 | | |
| | | 24 | | public void PlayClip() |
| | 32 | 25 | | { |
| | 32 | 26 | | audioSource.PlayOneShot(audioClip); |
| | 32 | 27 | | } |
| | | 28 | | } |