#Sprite Not Clickable

1 messages · Page 1 of 1 (latest)

deep dagger
#

Okay so you have a sprite, and it's box collider isn't acknowledging clicks

#

except halfway down

brisk walrus
#

wait a minute

deep dagger
#

?

#

k

brisk walrus
#

I think Ik the issue

deep dagger
#

ahh excellent

brisk walrus
#

how do I layer colliders?

deep dagger
#

You can't

#

one collider to rule them all

brisk walrus
#

(i have another collider right where that one is)

#

thats why its not working

deep dagger
#

yeah that'll do it

#

okay you have to pick ONE

#

whomever is "lower" on the hierarchy, their collider is "in front"

brisk walrus
#

but, what this collider is for is a button. The otherone is for a wall

brisk walrus
deep dagger
brisk walrus
#

just put it at the bottom of hierarchy?

#

no that doesn't work

#

changing the z layer also doesn't work

deep dagger
#

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

brisk walrus
#

thats why I didn't use it in the first place

deep dagger
brisk walrus
#

Thats what I have

#

With the collider

deep dagger
brisk walrus
#

I have a script with OnMouseDown on that “button”

deep dagger
# brisk walrus Yeah

Okay the object with that, can you highlight it in your hierarchy and send me a screenshot of the inspector

brisk walrus
#

except i made it a trigger

deep dagger
#

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

brisk walrus
#

yes

deep dagger
#

and the stage button is lower in the hierarchy than the wall?

brisk walrus
#

idk how to check that

#

i mean the wall is in the parent "StageAnimatronics"

deep dagger
#

in the world of Unity, anything at the bottom of the heirarchy is "on top" of the other things

deep dagger
brisk walrus
#

ohhhh

brisk walrus
#

also its not ui

deep dagger
brisk walrus
#

but canvas's are for ui I thought?

deep dagger
brisk walrus
deep dagger
#

standby family wants to talk to me

brisk walrus
#

I though canvas was ui only lol

brisk walrus
brisk walrus
#

camera can't find the player

#

shit breaking down

deep dagger
brisk walrus
deep dagger
#

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

brisk walrus
#

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

deep dagger
brisk walrus
#

like most things usually lol

deep dagger
#

okay I THINK I'm back

#

how are you faring?

brisk walrus
#

Haven't been able to figure it out

#

been modeling really though

deep dagger
#

well then I'll close the thread. Let me know if you still want help- when you want help

brisk walrus
#

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?

deep dagger
#

For example, you might be using OnCollsion when really, you need OnCollision2d

#

so that's an area that can go amiss

brisk walrus
#

Honestly is there just an easier way to make a button?

deep dagger
brisk walrus
#

wdym

deep dagger
#

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

deep dagger
#

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?

brisk walrus
deep dagger
brisk walrus
#

they don't use a rigid body

#

just a collider

deep dagger
#

okay just collider. hmm

#

okay try putting your wall switch to Layer 5 - UI - for science?

brisk walrus
#

the button? or the wall itself

#

well it doesn't matter cause it doesn't work both ways

deep dagger
brisk walrus
#

i tried both

#

neither worked

deep dagger
#

huh

#

okay give me un momento. I'll try making something similar and see if I can pull it off.

What version of Unity?

brisk walrus
deep dagger
#

okay cool I'm on that version as well

#

standby I gotta do a build.

brisk walrus
#

K

deep dagger
#

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"

brisk walrus
#

Hm ill have to look into that later

deep dagger
#

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.

brisk walrus
deep dagger
#

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

brisk walrus
#

so do I have to completely redo everything?

deep dagger
# brisk walrus 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

brisk walrus
deep dagger
# brisk walrus

make sure you are in your game view with you click the button

brisk walrus
#

the button just goes out of the map

deep dagger
# brisk walrus did you watch the video?

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.

brisk walrus
#

k

#

yeah I moved it and it still doesn't work

deep dagger
#

but it works fine by itself in a scene where nothing else exists?

brisk walrus
deep dagger
brisk walrus
#

huh

#

this is quite odd

deep dagger
#

only other thing I can think of is Pos Z needs to be changed

brisk walrus
#

I tried that as well

deep dagger
#

and I don't know how to help

brisk walrus
#

:(

deep dagger
#

You can try setting up a new version of the scene from scratch to see if that fixes it

#

it's annoying but I've solved problems that way