0

So I know that WebGL on mobile isn't fully supported, but I've gotten the game itself to run just fine. It just isn't registering touches. I have read that OnMouseDown will work on iOS anyway, and if it doesn't, there is a script that Unity supplies to convert mouse clicks to touches.

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

 #if UNITY_IPHONE || UNITY_WEBGL

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

 public class OnTouchDown : MonoBehaviour
 {
     void Update () 
     {
         Debug.Log ("AAAAAAAAAAA");
         // 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");
                     }
                 }
             }
     }
 }
 #endif

I have attached this script to the camera that renders the clickable objects, as instructed on the webpage, but to no avail. Here is the code utilizing OnMouseDown.

void OnMouseDown()
 {
     isClicked = true;
 }
 //Method to check if the correct letter was clicked
 public bool checkIfClicked(char letter)
 {
     //If the letter was clicked...
     if (isClicked == true)  
     {
         //If the letter is correct, return true and let SceneManager handle it
         if (gameObject.tag [0] == letter) 
         {
             return true;
         } 
         //If the letter is wrong...
         else 
         {
             //Change the letter to red
             gameObject.GetComponent<SpriteRenderer> ().color = Color.red;
             //Play the sound effect
             badSound.Play();
             //Decrement guesses remaining
             GameObject.Find("Scene Manager").GetComponent<SceneManage>().guessesRemaining--;
             //Update the textbox
             GameObject.Find("Scene Manager").GetComponent<SceneManage>().guessesText.text = ("Wrong guesses remaining: " + GameObject.Find("Scene Manager").GetComponent<SceneManage>().guessesRemaining);
             //Set the boolean to false
             isClicked = false;
         }
     }
     return false;
 }

Those methods work fine on desktop. So I'm just wondering if it's a mistake with my code, or it's just WebGL not being finished. Thanks!

gman
  • 100,619
  • 31
  • 269
  • 393
Mike OD
  • 117
  • 1
  • 12

0 Answers0