お世話になります。
現在タッチスクリーンをタップしたらキャラクターがそのタッチした場所に移動するスマホゲームを作っています。
問題は、Androidのスマホ上で、スクリーンをタッチしたところにキャラクターが移動するよう、
以下のように処理を作りましたが、Androidのスマホにビルドしたらスクリーンを
タッチしてもキャラクターがタッチした場所に移動せず、全く動かないことです。
下記画像のPlayer1オブジェクトにアタッチしたスクリプトの一部
C#
1void Update() 2 { 3 if (Input.touchCount > 0) 4 { 5 if (this.transform.position.y < BattleArea.myUpperSide) 6 { 7 Touch touch = Input.GetTouch(0); 8 Vector3 touchPosition = Camera.main.ScreenToWorldPoint(touch.position); 9 touchPosition.z = 10.0f; 10 this.transform.position = touchPosition; 11 } 12 }
BattleArea.myUpperSideの中身
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5namespace Common 6{ 7 public static class BattleArea 8 { 9 // 自エリア(ステージ)における各辺の座標 10 public const float myUpperSide = 195.0f; 11 public const float myLowerSide = -380.0f; 12 public const float myLeftSide = -690.0f; 13 public const float myRightSide = -190.0f; 14 } 15} 16
unity Remote 5を使った時は期待通りに動作しましたが、
実機では期待通りに動作しませんでした。
Vector3 touchPosition = Camera.main.ScreenToWorldPoint(touch.position);
の処理でCamera.main.ScreenToWorldPointを使っているので、
下記のUnity上の画像にあるように、Camera Previewか、Build And Run中に
No Cameras Renderingが表示されたことが問題かと思い、ネットで調べましたが、
解決策が見つかりませんでした。
androidの実機上でもタップした場所にキャラクターを移動させるためには
どうしたらよいでしょうか。
どうかアドバイスをよろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/20 18:18
2019/02/20 19:09