rony_y
rony_y

Reputation: 605

How do i use InControl with Unity UI?

I will be answering my own question

I have bought the InControll asset from the Unity asset store.

I want to use the asset with the Unity UI event system (and basically replace the Standalone Input Module) how so i achieve this ?

Upvotes: 0

Views: 714

Answers (1)

rony_y
rony_y

Reputation: 605

After some research and the helpful InControl docs on the subject that can be found here :

http://www.gallantgames.com/pages/incontrol-new-unity-gui

After adding your UI element (Button) an EventSystem object will be created on the scene.

Right click on the hierarchy -> InControl -> InputManager this will create an Input manager object.

Then select the Event System Game Object remove the Standalone Input Module from it and add the InControlInputModule to it.

Then with your custom script :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class MyScript: MonoBehaviour {

    public EventSystem eventSystem;
    public GameObject selectedObject;

    private bool buttonSelected = false;

    void Start () {
        eventSystem.SetSelectedGameObject (selectedObject);
    }

    void Update() {
       //To get which element is selected.
        print (eventSystem.currentSelectedGameObject.name);
    }

    private void OnDisable () {
        buttonSelected = false;
    }

}

You should be good to go after that again you may refer to link provided for a more in depth implantation.

Upvotes: 1

Related Questions