#Sprite Not Clickable
1 messages · Page 1 of 1 (latest)
Okay so you have a sprite, and it's box collider isn't acknowledging clicks
except halfway down
wait a minute
I think Ik the issue
ahh excellent
how do I layer colliders?
yeah that'll do it
okay you have to pick ONE
whomever is "lower" on the hierarchy, their collider is "in front"
but, what this collider is for is a button. The otherone is for a wall
oh ill do that then
Funny I was just dealing with this today
so how would I put the button one in front?
just put it at the bottom of hierarchy?
no that doesn't work
changing the z layer also doesn't work
well some good news Buttons ARE UI, and UI is programmed to always be on top of SPrites
And for that reason, I would say don't mix a button and UI
UI should be reserved for game menus and such - the things you absolutely WANT on top of your game world, and things you expect the game world to never block or interfer with
Instead, what you want is a clickable sprite
yeah put ui always follows the camera
thats why I didn't use it in the first place
Okay - Correct me if I'm wrong, but you said you have a Button component on one of your items right?
OnMouseDown
Thats what I have
With the collider
There is no Component named "OnMouseDown" that I am aware of. OnMouseDown is a function.
Yeah
I have a script with OnMouseDown on that “button”
Okay the object with that, can you highlight it in your hierarchy and send me a screenshot of the inspector
https://www.youtube.com/watch?v=-0eqAUkKQpI btw this is how I setup the collider thing
This is how to check if there's a mouse click on n object attached with collider(or collider2D) and then do anything you want :)
If you think this tutorial is useful,
don't forget to like - share - subscribe.
And here is my game for Android
https://play.google.com/store/apps/details?id=com.tawan.kiu
except i made it a trigger
Okay what I was looking for, was to make sure you didn't have the Unity Button Component on it. that's all
you have a custom class named Stage Button
yes
and the stage button is lower in the hierarchy than the wall?
You just checked it 🙂
in the world of Unity, anything at the bottom of the heirarchy is "on top" of the other things
How'com your stage button isn't in the Canvas?
ohhhh
cause when you said bottom I thought you wanted me to put it on the literal bottom lmao
also its not ui
still isn't working 😕
All your 2D things SHOULD be under your canvas
but canvas's are for ui I thought?
Canvas = all that is 2D
well what would that change anything?
It might
standby family wants to talk to me
I though canvas was ui only lol
aight
it just fucks everything up
camera can't find the player
shit breaking down
Hold-up. Your camera can't find the player when you put it in 2D?
when I put everything in the canvas
okay that's weird too
hey I don't think i can devote proper attention to this I keep getting called by my family and it's making it hard to focus on unraveling problems sorry
oh your good man
rn im working on the models, and its not like its that important till I get in later on in developing.
Im sure its an easy fix though
It probably is
like most things usually lol
ahh okay
well then I'll close the thread. Let me know if you still want help- when you want help
well right now
just finished a model rn lol
Ive tried to make the z axis larger, put it higher on the hierarchy, what else can I try
I mean is there a way besides using colliders to be able to click on something?
would something like this be a solution?
It can be multifaceted
For example, you might be using OnCollsion when really, you need OnCollision2d
so that's an area that can go amiss
Honestly is there just an easier way to make a button?
Im using the OnMouseDown
Well one way to debug is to isolate the item
wdym
make the button a prefab.
Then make a new scene, purely for testing purposes, and put the button in there and see if it works
if it doesn't even work right in a fresh scene, you've somehow hooked it up wrong
yeah works perfectly fine
Okay then the good news is that you hooked it fine
the bad news is you have some kind of z-fighting error.
Now you're saying you've got this button on top of a wall, and the wall also has a colider?
yes, to prevent the user from just walking through the walls out of the building
Are the wall colliders set to Kinematic?
okay just collider. hmm
okay try putting your wall switch to Layer 5 - UI - for science?
the button? or the wall itself
well it doesn't matter cause it doesn't work both ways
I was gonna say the button itself
huh
okay give me un momento. I'll try making something similar and see if I can pull it off.
What version of Unity?
K
okay I did a really silly quick scene setup, with a "fake wall" as a 2D Sprite, and a fake button that says "test me" so that is working
and I just added a random circle, and script with an OnMouseDown and it's working
and the circle is on top of the "Wall"
But I have everything organized under the Canvas, and the Canvas is set to "Screen Space Overlay"
Hm ill have to look into that later
sure thing.
If I recall correctly, there are a lot of 2D functions that don't work correctly once they are outside of the 2D Canvas.
If you take a full 2D tutorial course, the first thing that's usually done is they teach you how to setup your camera to work with your canvas properly. There are various "modes" a canvas can operate in.
"Screen Space -Camera" means the 2D elements stick to the camera and never move.
In Screen-Space - Overlay" , anything marked a UI sticks to the camera (buttons, UI text, etc,), but sprites do not, and it can be very useful for a top-down game like yours.
yeah if canvas aren't setup from teh get go they can get a lil funky. I just broke my 2D game mucking around with it 😛 But I'll get it fixed up
so do I have to completely redo everything?
Maybe? But maybe not. Try dragging your button and wall into your 2D Canvas first. and then if you notice it works FINE when under the canvas, but not when it's outside - then yeah you have to do something to make it work UNDER the canvas
make sure you are in your game view with you click the button
did you watch the video?
the button just goes out of the map
Yeah but you're just trying to test one thing.
So for this unique case, press play. Drop the switch to the Canvas. Then in scene view, physically move the button to the right space. Then in gameview, try clicking it
if it sudedenly works fine when under the canvas, then you have new knowledge.
but it works fine by itself in a scene where nothing else exists?
well yes, because there is no collider layering on top of it
the weird thing is that I was able to put a simple item on top of another collider, and it worked fine
only other thing I can think of is Pos Z needs to be changed
I tried that as well
well crap I'm sorry I don't know why yours is broke
and I don't know how to help
:(