Fully stuck on making a clickable game object system in unity

im fully stuck right now, I cant find a good solution for this problem, so basically im making a game similar to Coffee Talk where the player isnt really moving around, but theres clickable objects on the screen, and i have an interface and each of my objects implements that interface, my issue is that i cant really detect when theres a click on my object, im using game objects with a sprite renderer and i want to make it so that when a mouse is over them, the sprite for the game object switches to a different one that kinda shows what the object will do, i can NOT figure this out and have tried a bunch of different solutions. My other problem is that i cant detect when theres a click on my game objects, ive also tried alot for this and cant figure it out, if anyone has any advice i would really appreciate it
1 Reply
HerlockSholmes
HerlockSholmesOP11mo ago
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class Water : MonoBehaviour, IClickable
{
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(1))
{
Click();
}
}

void Drink()
{
gameObject.SetActive(false);
}

public void Click()
{
Drink();
}


}
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class Water : MonoBehaviour, IClickable
{
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(1))
{
Click();
}
}

void Drink()
{
gameObject.SetActive(false);
}

public void Click()
{
Drink();
}


}
thats a script i wrote to test it out but it just doesnt work i really dont know why nevermind i just figured out that using OnMouseDown u can easily make a game object clickable

Did you find this page helpful?