| | | 1 | | using BNG; |
| | | 2 | | using System.Diagnostics.CodeAnalysis; |
| | | 3 | | using UnityEngine; |
| | | 4 | | using HenryLab; |
| | | 5 | | |
| | | 6 | | [RequireComponent(typeof(AudioSource))] |
| | | 7 | | public class BallBounce : MonoBehaviour, IGrabbableEntity |
| | | 8 | | { |
| | | 9 | | [ExcludeFromCodeCoverage] |
| | | 10 | | public Grabbable Grabbable |
| | | 11 | | { |
| | | 12 | | get |
| | | 13 | | { |
| | | 14 | | var g = GetComponent<Grabbable>(); |
| | | 15 | | if(g) return g; |
| | | 16 | | return gameObject.AddComponent<Grabbable>(); |
| | | 17 | | } |
| | | 18 | | } |
| | | 19 | | [ExcludeFromCodeCoverage] public Transform Destination => null; |
| | | 20 | | |
| | | 21 | | [ExcludeFromCodeCoverage] public string Name => Str.Grabbable; |
| | | 22 | | |
| | | 23 | | [ExcludeFromCodeCoverage] |
| | | 24 | | public void OnGrabbed() |
| | | 25 | | { |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | public AudioClip collisionSound; // Sound clip for ball collision |
| | | 29 | | |
| | | 30 | | private AudioSource audioSource; // Reference to the AudioSource component |
| | | 31 | | |
| | | 32 | | private void Start() |
| | 1 | 33 | | { |
| | 1 | 34 | | audioSource = GetComponent<AudioSource>(); |
| | 1 | 35 | | audioSource.clip = collisionSound; |
| | 1 | 36 | | } |
| | | 37 | | |
| | | 38 | | private void OnCollisionEnter(Collision collision) |
| | 4 | 39 | | { |
| | | 40 | | // Play the collision sound if a collision occurs |
| | 4 | 41 | | if (collision.relativeVelocity.magnitude > 0.5f) |
| | 0 | 42 | | { |
| | 0 | 43 | | audioSource.PlayOneShot(collisionSound); |
| | 0 | 44 | | } |
| | 4 | 45 | | } |
| | | 46 | | |
| | | 47 | | public void OnReleased() |
| | 0 | 48 | | { |
| | 0 | 49 | | throw new System.NotImplementedException(); |
| | | 50 | | } |
| | | 51 | | } |