- Home /
How to make this buttons for Android?
Hey, guys. Someone knows why this didn't work on android ? XD Sorry, i'm new on Unity
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameController : MonoBehaviour
{
public string[,] tictactoeArray = new string[,]{ {"?", "?", "?"},
{"?", "?", "?"},
{"?", "?", "?"} };
//Row 1
public GameObject tictactoeButton00 = new GameObject();
public GameObject tictactoeButton01 = new GameObject();
public GameObject tictactoeButton02 = new GameObject();
//Row 2
public GameObject tictactoeButton10 = new GameObject();
public GameObject tictactoeButton11 = new GameObject();
public GameObject tictactoeButton12 = new GameObject();
//Row 3
public GameObject tictactoeButton20 = new GameObject();
public GameObject tictactoeButton21 = new GameObject();
public GameObject tictactoeButton22 = new GameObject();
public GameObject X = new GameObject();
public GameObject O = new GameObject();
int round = 0;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
if(hit.transform.name == tictactoeButton00.name && tictactoeArray[0,0]=="?") {
if(round % 2 == 0)
{
tictactoeArray[0,0] = "X";
round++;
Instantiate(X, new Vector3(tictactoeButton00.transform.position.x, tictactoeButton00.transform.position.y, tictactoeButton00.transform.position.z), Quaternion.identity);
}
else {
tictactoeArray[0,0] = "O";
round++;
Instantiate(O, new Vector3(tictactoeButton00.transform.position.x, tictactoeButton00.transform.position.y, tictactoeButton00.transform.position.z), Quaternion.identity);
}
}
}
}
}
private void OnMouseDown()
{
}
}
Comment
Answer by BuzzyRoboYT · Jan 18 at 12:49 PM
You used Input.GetMouseButtonDown. Mobiles dont have a mouse button. Try looking up mobile touch input.
Your answer
Follow this Question
Related Questions
(Mobile) Touch anywhere on screen EXCEPT button 3 Answers
Why this simple code doesnt work? 0 Answers
I need my play button to load level 1 when the player touches the play button 2 Answers
Convert Mouse Input to Touch Input 0 Answers
Receiving UI/touch events while mobile soft keyboard is open 0 Answers