前提・実現したいこと
2Dシューティングゲームで、時機を移動させたいですが、移動できません!
色々調べましたが、限界でした
unity上および実機のandroidにビルドしたときに動かせるように対応したいです
該当ソースはたくさんありますが、どのファイルをここに張ればよいのかもわからないので、
原因の特定に足りない情報があれば随時いってもらいたいと思っています><
発生している問題・エラーメッセージ
該当のソースコード
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class RocketController : MonoBehaviour { 6 public GameObject bulletPrefab; 7 private float timeElapsed; 8 private Vector2 touchPosition; 9 10 // Use this for initialization 11 void Start () { 12 13 } 14 15 // Update is called once per frame 16 void Update() { 17 timeElapsed += Time.deltaTime; 18 if (Application.platform == RuntimePlatform.Android) { 19 touchPosition = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position); 20 } 21 22 //if (Input.GetKey(KeyCode.LeftArrow) && transform.position.x > -2.5f) { 23 // transform.Translate(-0.1f, 0, 0); 24 //} 25 //if (Input.GetKey(KeyCode.RightArrow) && transform.position.x < 2.5f) { 26 // transform.Translate(0.1f, 0, 0); 27 //} 28 // プラットフォームによらないマウス・タッチ判定 29 if (Input.GetMouseButton(0)) { 30 if (touchPosition.x > transform.position.x && transform.position.x < 2.5f) { 31 transform.Translate(0.1f, 0, 0); 32 } 33 if (touchPosition.x < transform.position.x && transform.position.x > -2.5f) { 34 transform.Translate(-0.1f, 0, 0); 35 } 36 if (Input.mousePosition.x > transform.position.x && transform.position.x < 2.5f) { 37 transform.Translate(0.1f, 0, 0); 38 } 39 if (Input.mousePosition.x < transform.position.x && transform.position.x > -2.5f) { 40 transform.Translate(-0.1f, 0, 0); 41 } 42 } 43 44 if (Input.GetKeyDown(KeyCode.Space)) { 45 Instantiate(bulletPrefab, transform.position, Quaternion.identity); 46 } 47 48 // androidのときは1秒ごと発射 49 if (Application.platform == RuntimePlatform.Android) { 50 if (timeElapsed >= 1.0f) { 51 Instantiate(bulletPrefab, transform.position, Quaternion.identity); 52 53 timeElapsed = 0.0f; 54 } 55 } 56 } 57} 58
試したこと
getmousebutton(0),mousepositionなど試しましたが動きませんでした
サンプルサイトを基にして作ったので、当初はPC対応のところはコメントアウトしている部分で実現できていたのですが、全体的にandroid対応の方法がわかりませn
補足情報(FW/ツールのバージョンなど)
unity2017.f4.1
全然何もわかりませんが、何か少しでも手掛かりをよろしくお願いします。。。
ちなみにunityの画像はなぜか添付できませんでした。。
そもそもフレームワーク?ライブラリ?一つ導入すれば解決できる問題なのであれば導入するべき場所なんかも教えてもらえるとありがたいです
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。