How can I create a touch event or UI button that can execute the code below. I got that code from an asset that meant for PC i want to re-create that project for android mobile
using UnityEngine;
using System.Collections;
public class PlayerIO : MonoBehaviour {
RaycastHit hit;
int maxBuildDist = 10;
public Transform RetAdd;
public Transform RetDelete;
public Transform Player;
public GameObject Player_Camera;
Color Block_Color = Color.blue;
bool Block_Menu = false;
void Start(){
RetAdd = GameObject.Find("RetAdd").transform;
RetDelete = GameObject.Find("RetDel").transform;
Player = GameObject.FindGameObjectWithTag("Player").transform;
Player_Camera = GameObject.Find("Main Camera");
}
void Update(){
if(Input.GetKeyDown(KeyCode.E))
Block_Menu = !Block_Menu;
if(Block_Menu){
Time.timeScale = 0;
Player.GetComponent<MouseLook>().enabled = false;
Player_Camera.GetComponent<MouseLook>().enabled = false;
//((MonoBehaviour)Player.GetComponent<FPSInputController>()).enabled = false;
}
if(!Block_Menu){
Time.timeScale = 1;
Player.GetComponent<MouseLook>().enabled = true;
Player_Camera.GetComponent<MouseLook>().enabled = true;
//((MonoBehaviour)Player.GetComponent<FPSInputController>()).enabled = true;
}
if(!Block_Menu){
if(Physics.Raycast(Camera.main.ScreenPointToRay(new Vector3((Screen.width / 2), (Screen.height / 2), 0)), out hit, maxBuildDist)){
RetAdd.GetComponent<Renderer>().enabled = true;
if(hit.transform.tag == "Block"){
RetAdd.transform.position = hit.transform.position + hit.normal;
RetDelete.transform.position = hit.transform.position;
RetDelete.GetComponent<Renderer>().enabled = true;
}
if(hit.transform.tag != "Block"){
RetDelete.GetComponent<Renderer>().enabled = false;
RetAdd.transform.position = new Vector3(hit.point.x, hit.point.y + 0.5f, hit.point.z);
}
if(Input.GetMouseButtonDown(0)){
GameObject block = (GameObject)Instantiate(Resources.Load("Block01"), RetAdd.transform.position, Quaternion.identity);
block.GetComponent<Renderer>().material.color = Block_Color;
}
else if(Input.GetMouseButtonDown(1) && hit.transform.tag != "Floor"){
Destroy(hit.transform.gameObject);
}
}
else{
RetAdd.GetComponent<Renderer>().enabled = false;
RetDelete.GetComponent<Renderer>().enabled = false;
}
}
}
void OnGUI(){
if(Block_Menu)
Block_Menu_GUI();
}
void Block_Menu_GUI(){
GUILayout.BeginVertical();
if(GUILayout.Button("Green"))
Block_Color = Color.green;
if(GUILayout.Button("Red"))
Block_Color = Color.red;
if(GUILayout.Button("Blue"))
Block_Color = Color.blue;
GUILayout.EndVertical();
}
}
this is the whole code of the script that I want to change. I already had a joystick control but the problem is since I'm using that OnMouseDown whenever I click my joystick the object is spawning