Jump to content

[SOLVED!] Clickable IVA Props?


Recommended Posts

Hi all,

I'm trying to make a simple monitor that will change the picture when you click on it. I know how to change the picture, but thus far I can't figure out how to detect the mouse click on the monitor. I know it can be done; Raster Prop Monitor lets you tap on buttons and they do stuff. Here's my setup for the monitor:

wv7IFV0.png

As you can see, I've added a box collider. I've tried setting it to a trigger and just leaving it as is, but to no effect. I've also set it to trigger and put the collider on the Part Triggers layer, but that didn't help.

Below is code I adapted from Raster Prop Monitor's SmarterButton class. I can find the ScreenTrigger no problem and add the ButtonClickWatcher, but still cannot detect the mouse click.

    public class ButtonClickWatcher : MonoBehaviour
    {
        protected bool mouseDown;

        public void OnMouseDown()
        {
            mouseDown = true;
            Debug.Log("FRED OnMouseDown");
        }

        public void OnMouseUp()
        {
            mouseDown = false;
            Debug.Log("FRED OnMouseUp");
        }
    }

    public class InternalScreenSwitcher : InternalModule
    {
        public void Start()
        {
            if (HighLogic.LoadedSceneIsFlight == false)
                return;

            Transform trans = internalProp.FindModelTransform("ScreenTrigger");
            if (trans != null)
            {
                Debug.Log("FRED found trigger transform");
                GameObject goButton = trans.gameObject;
                if (goButton != null)
                {
                    ButtonClickWatcher clickWatcher = goButton.GetComponent<ButtonClickWatcher>();
                    if (clickWatcher == null)
                    {
                        clickWatcher = goButton.AddComponent<ButtonClickWatcher>();
                        Debug.Log("FRED created click watcher");
                    }
                }
            }
        }
    }

This is what I found from Unity Script. It looks like I'm setting up the behavior correctly. Any ideas why I'm not able to detect the mouse click?

Edited by Angel-125
Link to comment
Share on other sites

4 hours ago, Hary R said:

A wild guess, shouldn't your collider in unity set to" is trigger"?

Yup, already tried that. I set it to Is Trigger, left the layer on Default, and set it to Is Trigger with the layer set to Part Triggers. Both cases don't result in detecting the mouse click.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...