Android clicking to touch
Asked Answered
P

2

0

Hi, I am trying to convert my game from windows standalone to an android build.

My issue is for clicking an object i use OnMouseUp function but on android this function doesn’t work.

is there any function for android that works the same but for touching?
i have searched the Script reference but couldn’t find any functions for it.

Thanks in advance, Sycohazza.

Phaih answered 5/6, 2012 at 18:2 Comment(0)
A
0

There is this code that makes OnMouseDown work for multiple fingers on real objects with colliders, you could use this or modify it for OnMouseUp…

//  OnTouchDown.cs
//  Allows "OnMouseDown()" events to work on the iPhone.
//  Attach to the main camera.

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

public class OnTouchDown : MonoBehaviour
{
    void Update () {
        // Code for OnMouseDown in the iPhone. Unquote to test.
        RaycastHit hit = new RaycastHit();
        for (int i = 0; i < Input.touchCount; ++i) {
            if (Input.GetTouch(i).phase.Equals(TouchPhase.Began)) {
            // Construct a ray from the current touch coordinates
            Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
            if (Physics.Raycast(ray, out hit)) {
                hit.transform.gameObject.SendMessage("OnMouseDown");
              }
           }
       }
    }
}
Anent answered 6/6, 2023 at 1:39 Comment(4)

Oh wow i was just using raycast like this about a week ago. Cant believe i didnt think of this, thanks :)

Phaih

what is the equivalent of this for javascript..?

Venetian

Just stick it in a plugins folder and you can use it from either language

Anent

hello ! can we have this code for android please ? It's doesn't work for me :'(

Antisepticize
T
0

isn’t suit for android mobile?

Torse answered 28/11, 2012 at 11:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.