Hey all, I’m trying to click on an object with my mouse and run some script (to change what controllers are active - have that part figured out). I’ve searched and read through about 20 similar forum threads and I’m not sure what I’m doing wrong. I’d prefer to use an event rather than casting a ray during Update(). Help please :). I have a button in my scene with a sphere collider (trigger unchecked) and a script named ButtonFlyShip. The ButtonFlyShip script includes the code:
I’ve also tried simply using OnMouseUp(), but I never enter that event either. I’m running the game through the Unity play button, and trying to click on the object using the center of the screen and/or my actual Windows mouse icon. Ideas? Thanks!
Thanks. That didn’t work either, but on a whim, I added the ButtonFlyShip to a really large item in the world and tried clicking on that. It worked! So now I’m curious about the mouse aim and where it’s clicking. I did this:
I don’t see a ray. Perhaps I don’t see it because it’s a line with no width and I can’t see it from the end? How can I debug visually where exactly any mouse click ray will hit?
Camera perspective: I was already running in Perspective
I was using a SphereColider.
I tried using Debug.DrawLine, and I still can’t see my line.
I did finally get to enter OnMouseUpAsButton() when I wanted. Again, on a whim, I looked up the hotkey for Playing my game through the Unity program (Ctrl+p), centered my mouse in the play window, and started playing - I could get the mouse event to fire for my large object, but not my intended button no matter what. Compared the colliders and they looked the same, so I just deleted and recreated the collider on my button and it works now. Also of note is I’ve determined that the actual Window’s mouse icon denotes where your in-game mouse is, not the center of my camera. I’m unsure how that works when I build and execute a full-screen exe of my game, but I’ll cross that road later I suppose.