AtomCraft-2.28/AtomURP-main/Assets/GrabbableObject.cs
2024-03-13 12:24:01 +01:00

38 lines
735 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GrabbableObject : MonoBehaviour
{
private AudioSource audioSource;
private Rigidbody rb;
void Start()
{
// Get the AudioSource component
audioSource = GetComponent<AudioSource>();
// Get the Rigidbody component
rb = GetComponent<Rigidbody>();
}
void OnMouseDown()
{
GrabObject();
}
void GrabObject()
{
// Play sound clip
if (audioSource != null)
{
audioSource.Play();
}
// Perform grab logic here
// For example, disable physics to hold the object in place
rb.isKinematic = true;
}
}