Forum rules - please read before posting.

Mobile touch to interact with "E" button created via third party script

Hi All,

I brought an asset from unity store. Its a house that has doors and drawers opening and closing using the "e" button on the keyboard. Given I am using it for mobile, how do I convert the "e" input.getkeydown to touch opening and closing?

I am getting proficient at creating moveables via AC. Prefer not to reinvent the wheel when there is something already created.

This is the script to interact with doors/drawers.

void Update () {
    Ray ray = cam.ViewportPointToRay (new Vector3 (0.5f, 0.5f, 0));
    RaycastHit hit;

    if (Physics.Raycast (ray, out hit, rayDistance)) {
        if (hit.transform.GetComponent<SuburbanHouse.Door> ()) {
            crossHairStatus = 1;
            if (Input.GetKeyDown (KeyCode.E)) {
                Door d = hit.transform.GetComponent<Door> ();
                d.InteractWithThisDoor ();
            } 
        } else if (hit.transform.GetComponent<GarageDoor> ()) {
            crossHairStatus = 1;
            if (Input.GetKeyDown (KeyCode.E)) {
                GarageDoor gd = hit.transform.GetComponent<GarageDoor> ();
                gd.ToggleDoor ();
            }
        } else {
            crossHairStatus = 0;
        }
    } else {
        crossHairStatus = 0;
    }

}

Comments

  • What kind of behaviour are you looking for?

    The code above doesn't seem necessary given AC's Hotspots essentially serve the same purpose. Within the Hotspot's Interaction ActionList, you can run an Object: Call event Action or Object: Send message Action to trigger the two custom functions that code refers to (i.e. InteractWithThisDoor and ToggleDoor).

    If you really want to use the above code, you could try replacing:

    Input.GetKeyDown (KeyCode.E)
    

    with:

    AC.KickStarter.playerInput.GetButtonDown ("CustomUse")
    

    The code should then respond to input simulated via an AC Menu Button. Create a new Menu with a Button element, set it's "Click type" to "Simulate Input" and have it simulate a Button named "CustomUse".

  • Thank you Chris. The first option did work with ease.
    I did look around about "sending messages" earlier but couldn't work it out. Eventually, I worked out how it should be applied after seeing your response.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.