Ok so I’ve been trying to get a video overlay to play when the mouse is hovered over a collider hidden in the scene.
I’ve rewritten the code for it about 10x now and even added a tracker to the mouse to feed information to the video overlay and nothing.
So I started over again to see if it was just the video part of it. So I started and made a new script to see if it’s the collider or the mouse by seeing if it’ll just at least make a noise and I got nothing.
If anyone has any solutions it’d be helpful I’m at a dead end and I think it has to do something with the software at this point.
Here’s a look at the mouse tracker and the noise trigger.
MOUSE TRACKER:
"using UnityEngine;
public class CursorTracker : MonoBehaviour
{
private Vector2 cursorPosition; // The current position of the cursor
private void Update()
{
// Get the cursor's position in world coordinates
cursorPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
// Optional: Log the cursor's position to the console
Debug.Log("Cursor Position: " + cursorPosition);
}
// Method to get the current cursor position
public Vector2 GetCursorPosition()
{
return cursorPosition;
}
}"`
SOUND HOVER TRIGGER
`"using UnityEngine;
public class HoverSoundPlayer : MonoBehaviour
{
public AudioClip hoverSound; // The sound to play on hover
private AudioSource audioSource; // Reference to the AudioSource component
private CursorTracker cursorTracker; // Reference to the CursorTracker component
private void Start()
{
// Get or add an AudioSource component
audioSource = GetComponent<AudioSource>();
if (audioSource == null)
{
audioSource = gameObject.AddComponent<AudioSource>();
}
// Ensure the audioSource does not play on awake and loops the sound
audioSource.playOnAwake = false;
audioSource.loop = false;
// Find the CursorTracker component in the scene
cursorTracker = FindObjectOfType<CursorTracker>();
if (cursorTracker == null)
{
Debug.LogWarning("CursorTracker component not found in the scene.");
}
}
private void Update()
{
// Optionally: Use the cursor position for custom logic
if (cursorTracker != null)
{
Vector2 cursorPos = cursorTracker.GetCursorPosition();
// Example: Log cursor position or use it for other purposes
Debug.Log("Current Cursor Position: " + cursorPos);
}
}
private void OnMouseEnter()
{
// Play the hover sound when the cursor enters the collider
if (audioSource != null && hoverSound != null)
{
audioSource.clip = hoverSound;
audioSource.Play();
Debug.Log("Playing hover sound: " + hoverSound.name);
}
else
{
Debug.LogWarning("HoverSoundPlayer: AudioSource or hoverSound not set.");
}
}
private void OnMouseExit()
{
// Stop the sound when the cursor exits the collider
if (audioSource != null && audioSource.isPlaying)
{
audioSource.Stop();
Debug.Log("Stopping hover sound.");
}
}
}