Как я могу добавить поддержку сенсорного экрана для ОС Android в сценарий моего проигрывателя в Unity С#?

Мне нужно добавить сенсорное управление в мою игру, я не знаю, как это сделать. В моей игре шкала времени очень важна, я прочитал много руководств, и это не работает. Я думаю о чем-то вроде половины экрана слева и половины экрана справа, карта — это дорога, но я думаю, что это не важно. Помоги мне, пожалуйста.

Это игра, как бесконечный бегун. Я очень плохо разбираюсь в сценариях.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerBehaviour : MonoBehaviour {
public float death =0f;
public float timee;
public float points = 0f;
public float distance = 0f;
void Start ()
{
    timee = Time.timeScale;
}




void Update ()
{

    if (Input.GetKey(KeyCode.A) && transform.position.x <12.5f && transform.position.x >-2.5f)
    {
        GameObject.Find("player").transform.position -= new Vector3((Time.deltaTime * 3.5f )* timee ,0, 0);
    }
    if (Input.GetKey(KeyCode.D) && transform.position.x < 2.5f && transform.position.x > -12.5f)
    {
        GameObject.Find("player").transform.position += new Vector3((Time.deltaTime * 3.5f) * timee , 0, 0);
    } 
    distance = distance + 15 * Time.deltaTime;
}
public float score;
void OnCollisionEnter2D(Collision2D col)
{
    if (col.gameObject.tag == "siema") 
    {
        if (score < 33)
        {
            score++;
            Time.timeScale = 1f+ score * 0.03f;
            timee = 1f - (0.04f * score);
            if (timee < 0.5f && score <= 33)
            {
                timee = 0.5f;
            }
            if (score > 29) 
            {
                timee = 0.4f;
            }
        }
    }

        if (col.gameObject.tag == "base") 
        {
            points = points + score * score;
            score = 0f;
        }
        if (score == 0) 
        {
            Texture texture = Resources.Load<Texture> ("0");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
            Time.timeScale = 1f;
            timee = 1f;
        }
        if (score == 1) {
            Texture texture = Resources.Load<Texture> ("1");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;

        }
        if (score == 2) {
            Texture texture = Resources.Load<Texture> ("2");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;


        }
        if (score == 3) {
            Texture texture = Resources.Load<Texture> ("3");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;

        }
        if (score == 4) {
            Texture texture = Resources.Load<Texture> ("4");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
        if (score == 5) {
            Texture texture = Resources.Load<Texture> ("5");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
        if (score == 6) {
            Texture texture = Resources.Load<Texture> ("6");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
        if (score == 7) {
            Texture texture = Resources.Load<Texture> ("7");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
        if (score == 8) {
            Texture texture = Resources.Load<Texture> ("8");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
        if (score == 9) {
            Texture texture = Resources.Load<Texture> ("9");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
        if (score == 10) {
            Texture texture = Resources.Load<Texture> ("10");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
        if (score == 11) {
            Texture texture = Resources.Load<Texture> ("11");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
        if (score == 12) {
            Texture texture = Resources.Load<Texture> ("12");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
        if (score == 13) {
            Texture texture = Resources.Load<Texture> ("13");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
        if (score == 14) {
            Texture texture = Resources.Load<Texture> ("14");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
        if (score == 15) {
            Texture texture = Resources.Load<Texture> ("15");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
        if (score == 16) {
            Texture texture = Resources.Load<Texture> ("16");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
        if (score == 17) {
            Texture texture = Resources.Load<Texture> ("17");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
        if (score == 18) {
            Texture texture = Resources.Load<Texture> ("18");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
        if (score == 19) {
            Texture texture = Resources.Load<Texture> ("19");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
        if (score == 20) {
            Texture texture = Resources.Load<Texture> ("20");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
        if (score == 21) {
            Texture texture = Resources.Load<Texture> ("21");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
        if (score == 22) {
            Texture texture = Resources.Load<Texture> ("22");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
        if (score == 23) {
            Texture texture = Resources.Load<Texture> ("23");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
        if (score == 24) {
            Texture texture = Resources.Load<Texture> ("24");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
        if (score == 25) {
            Texture texture = Resources.Load<Texture> ("25");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
        if (score == 26) {
            Texture texture = Resources.Load<Texture> ("26");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
        if (score == 27) {
            Texture texture = Resources.Load<Texture> ("27");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
        if (score == 28) {
            Texture texture = Resources.Load<Texture> ("28");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }   
        if (score == 29) {
            Texture texture = Resources.Load<Texture> ("29");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }   
        if (score == 30) {
            Texture texture = Resources.Load<Texture> ("30");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
        if (score == 31) {
            Texture texture = Resources.Load<Texture> ("31");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }   
        if (score == 32) {
            Texture texture = Resources.Load<Texture> ("32");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }   
        if (score == 33) {
            Texture texture = Resources.Load<Texture> ("33");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
        }
    if (col.gameObject.tag == "siema") 
    {
        Destroy (col.gameObject);
    }
    if (col.gameObject.tag == "blocade")
    {
        if (score > 0)
        {
            score = 0;
            Texture texture = Resources.Load<Texture> ("0");
            GameObject.Find ("player").GetComponent<Renderer> ().material.mainTexture = texture;
            Time.timeScale = 1f;
            timee = 1f;
            Destroy (col.gameObject);
        } 
        death++;
        Destroy (col.gameObject);
        if (death == 2)
        {
            Time.timeScale = 0.0001f;
        }
    }
}
}

person Rayan BlackBurn    schedule 12.08.2017    source источник
comment
Это не минимальный пример вашей проблемы; обновите свой вопрос.   -  person Jeroen Heier    schedule 12.08.2017


Ответы (1)


Если вы имеете в виду что-то вроде джойстика, вы можете добавить его из стандартных ресурсов Unity - CrossPlatformInput - prefab - Mobile single stick control

person Tem    schedule 12.08.2017