前提
unityremoteを利用してスマホの画面からでも正常に動作することを確かめようとしたが、なぜか再生プラットフォームがwindowsEditerになってしまい、再生プラットフォームをAndroidにすることができない
該当のソースコード(長いので必要な部分のみ updateの部分が問題の箇所)
cs
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class PlayerController : MonoBehaviour 6{ 7 [SerializeField] GameObject attackHit = null; 8 [SerializeField] ColliderCallReceiver footColliderCall = null; 9 [SerializeField] float jumpPower = 20f; 10 Animator animator = null; 11 Rigidbody rigid = null; 12 bool isAttack = false; 13 bool isGround = false; 14 bool isTouch = false; 15 float horizontalKeyInput = 0; 16 float verticalKeyInput = 0; 17 Vector2 leftStartTouch = new Vector2(); 18 Vector2 leftTouchInput = new Vector2(); 19 // Start is called before the first frame update 20 void Start() 21 { 22 animator = GetComponent<Animator>(); 23 rigid = GetComponent<Rigidbody>(); 24 attackHit.SetActive(false); 25 26 // FootSphereのイベント登録 27 footColliderCall.TriggerStayEvent.AddListener(OnFootTriggerStay); 28 footColliderCall.TriggerExitEvent.AddListener(OnFootTriggerExit); 29 } 30 31 // Update is called once per frame 32 void Update() 33 { 34 Debug.Log(Application.platform); 35 if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) 36 { 37 Debug.Log("OSチェック"); 38 // スマホタッチ操作 39 // タッチしている指の数が0より多い 40 if (Input.touchCount > 0) 41 { 42 Debug.Log("タッチしている"); 43 isTouch = true; 44 // タッチ情報をすべて取得 45 Touch[] touches = Input.touches; 46 foreach (var touch in touches) 47 { 48 bool isLeftTouch = false; 49 bool isRightTouch = false; 50 if (touch.position.x > 0 && touch.position.x < Screen.width / 2) 51 { 52 isLeftTouch = true; 53 } 54 else if (touch.position.x > Screen.width / 2 && touch.position.x < Screen.width) 55 { 56 isRightTouch = true; 57 } 58 if (isLeftTouch == true) 59 { 60 // タッチ開始 61 if (touch.phase == TouchPhase.Began) 62 { 63 Debug.Log("タッチ開始"); 64 leftStartTouch = touch.position; 65 } 66 // タッチ中 67 else if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary) 68 { 69 Debug.Log("タッチ中"); 70 Vector2 position = touch.position; 71 leftTouchInput = position - leftStartTouch; 72 } 73 // タッチ終了 74 else if (touch.phase == TouchPhase.Ended) 75 { 76 Debug.Log("タッチ終了"); 77 leftTouchInput = Vector2.zero; 78 } 79 } 80 if (isRightTouch == true) 81 { 82 83 } 84 } 85 } 86 else 87 { 88 isTouch = false; 89 // Debug.Log("何かしらが原因でAndroidプラットフォーム判定がされていない"); 90 } 91 } 92 else 93 { 94 Debug.Log("PC操作です"); 95 // PCキー入力取得 96 horizontalKeyInput = Input.GetAxis("Horizontal"); 97 verticalKeyInput = Input.GetAxis("Vertical"); 98 } 99 100 101 102
試したことや考察など
ある教材の通りに「プレイヤーをスマホのタッチ操作で移動させる」という作業をしています。ですが、上手く行きませんでした。
1 これまで行った操作に間違いがある可能性
・教材では、Device Simulatorを使用して作業をしていましたが、どうやら現在のUnity(2021.3.10f1)ではSimulatorが常設されたようなので、パッケージマネージャを使用してDevice SimulatorをインストールしなくてもSimulatorを操作できるようです。そのため、Device Simulatorのインストールの部分をスキップして作業を進めました。
・その後画像のような設定を行いました。
・Unityremoteはこちらのサイトを参考に設定を確認しました
・buildsettingはAndroidになっています。
2 どこでエラー(意図せぬ挙動)が起きているのか
・デバッグログを仕込んだ(上のコードの通り)ところ、以下のことが判明しました。
・ Debug.Log(Application.platform);を記述すると、なぜか「WindowsEditor」が表示される。*本来なら、ここにAndroidが出てくる(と予想していた)。
・また、実際に接続しているAndroid端末では一応ボタンクリックによる操作は正常に動作していた。*これはスマホ上でwendows用のモードで動いていたから。
・Unityremoteを使用せずに実際にbuildして動作確認を行った際は上手く動いた(Android端末でクリック、フリック操作ができた。*今作成しているアプリケーションとは別のものではあるが)
ここで詰まってしまいました。なぜ再生プラットフォームがAndroidにならないのでしょうか?何かしらアドバイスをいただければ幸いです。もし不備があれば追記いたします。よろしくお願いいたします。
追記
恐らくプラットフォームをAndroidに出来れば正常に動作しそうです。ですが、現在buildsettingをAndroidに設定しているため、恐らくプラットフォームはAndroidになっているはずです。(実際にはWindowsになってしまっているようではあるが)現時点ではとりあえず、条件分岐を無視してスマホ専用に開発を進めています。

下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
また依頼した内容が修正された場合は、修正依頼を取り消すようにしましょう。
2022/09/27 11:21
2022/09/28 00:04