2017-08-12 7 views
0

ゲームにタッチコントロールを追加する必要がありますが、その操作方法はわかりません。 私のゲームの時間スケールは非常に重要です 私は多くのチュートリアルを読みましたが、これはうまくいきません。 左半画面と半画面右半分のようなものを考えます 地図は道路ですが、これは重要ではないと思います。 お願いします。アンドロイドOSのタッチサポートをプレイヤースクリプトにユニティC#で追加するにはどうすればよいですか?

これは無限のランナーのようなゲームです。 私はスクリプト作成が非常に少ないです。あなたは、ジョイスティックのようなものを意味する場合

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

これはあなたの問題の最小限の例ではありません。あなたの質問を更新してください。 –

答えて

0

あなたはユニティ標準の資産からそれを追加することができます - CrossPlatformInputを - プレハブを - モバイルシングルスティック制御

関連する問題