mirror of
https://github.com/noakdsv/AtomCraft-2.28.git
synced 2025-12-13 16:35:13 +01:00
67 lines
1.4 KiB
C#
67 lines
1.4 KiB
C#
using UnityEngine;
|
|
|
|
public class InteractableObject : MonoBehaviour
|
|
{
|
|
public AudioClip neutronClip;
|
|
public AudioClip protonClip;
|
|
public AudioClip electronClip;
|
|
|
|
private AudioSource audioSource;
|
|
|
|
void Start()
|
|
{
|
|
audioSource = GetComponent<AudioSource>();
|
|
}
|
|
|
|
void OnTriggerEnter(Collider other)
|
|
{
|
|
if (other.CompareTag("Player"))
|
|
{
|
|
PlaySound();
|
|
}
|
|
}
|
|
|
|
void OnCollisionEnter(Collision collision)
|
|
{
|
|
if (collision.gameObject.CompareTag("Player"))
|
|
{
|
|
PlaySound();
|
|
}
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (Input.GetMouseButtonDown(0)) // Change this condition as per your requirement
|
|
{
|
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
RaycastHit hit;
|
|
|
|
if (Physics.Raycast(ray, out hit))
|
|
{
|
|
if (hit.collider.gameObject == gameObject)
|
|
{
|
|
PlaySound();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void PlaySound()
|
|
{
|
|
if (gameObject.CompareTag("Neutron"))
|
|
{
|
|
audioSource.clip = neutronClip;
|
|
}
|
|
else if (gameObject.CompareTag("Proton"))
|
|
{
|
|
audioSource.clip = protonClip;
|
|
}
|
|
else if (gameObject.CompareTag("Electron"))
|
|
{
|
|
audioSource.clip = electronClip;
|
|
}
|
|
|
|
audioSource.Play();
|
|
}
|
|
}
|