2017-08-12 2 views
0

Je dois ajouter des commandes tactiles dans mon jeu, je ne sais pas comment le faire. Dans mon jeu, l'échelle de temps est très importante. J'ai lu beaucoup de tutoriels et cela ne fonctionne pas. Je pense à quelque chose comme demi-écran gauche et demi-écran droite la carte est la route, mais je pense que ce n'est pas important. Aidez-moi s'il vous plaît.Comment puis-je ajouter un support tactile pour Android OS à mon script de lecteur dans unity C#?

Ceci est un jeu comme un coureur infini. Je suis très faible sur les scripts.

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; 
     } 
    } 
} 
} 
+0

Ce n'est pas un exemple minimal de votre problème; mettez à jour votre question. –

Répondre

0

Si vous voulez dire quelque chose comme joystick vous pouvez l'ajouter de l'unité des actifs standards - CrossPlatformInput - maison préfabriquée - contrôle simple bâton mobile