0

I want to print held when I touch only the gameObject

public GameObject Gameobject;   
void Update () {
        if (Input.GetButton("Fire1"))
        {
            print("held");
        }
    }

So this code prints held when I even touch outside the gameobject.I added the script to the gameobject.The answer must work on android too.

QWSA ZASZ
  • 25
  • 1
  • 7
  • 1
    @Programmer I tried `OnDrag` method from your duplicate answer. And this works Perfectly :) – QWSA ZASZ Aug 29 '17 at 18:09
  • [How to open keyboard on android in UNITY?](https://stackoverflow.com/questions/46501514/how-to-open-keyboard-on-android-in-unity) – QWSA ZASZ Sep 30 '17 at 09:41

1 Answers1

0

There is event called OnMouseOver()

void OnMouseOver()
{
    if (Input.GetAxis("Fire1"))
        {
            print("held");
        }
}

For Android is different, here you have a link:

http://answers.unity3d.com/questions/610440/on-touch-event-on-game-object-on-android-2d.html

They explain how to get the position of the touch and shoot a ray to know if it impacts your object.

NorbyAriel
  • 26
  • 4