using System.Collections; using System.Collections.Generic; using UnityEngine; //タッチした場所やオブジェクトを取得する、レイヤー名の一致判定といった処理 public class SupportScreenTouch : MonoBehaviour { RaycastHit hit; Ray ray; //========================================================= //タッチしたオブジェクトの取得 //========================================================= //Rayを飛ばし、当たったコライダーのオブジェクトを返す public GameObject RayHitReturnObj(Vector3 mousePos) { GameObject obj = RayHit(mousePos).collider.gameObject; if (obj == null) { Debug.Log("オブジェクトが取得できない"); } //Debug.Log(obj.name); return obj; } //Rayの処理をし、当たった位置を返す public Vector3 RayHitReturnHitPoint(Vector3 mousePos) { return RayHit(mousePos).point; } //Rayを飛ばし、当たった情報を返す RaycastHit RayHit(Vector3 mousePos) { ray = Camera.main.ScreenPointToRay(mousePos); if (Physics.Raycast(ray, out hit)) return hit; Debug.Log("Rayが何も取得していない"); return hit; } //========================================================= //レイヤー名が取得したいオブジェクトと同一であるかを返す //========================================================= public bool IsLayerNameToMatch(GameObject obj, string trueName) { if(IsLayerNameObj(obj) == null) { Debug.Log("ここがいけない falseを返します"); return false; } if (IsLayerNameObj(obj) == trueName) return true; return false; } //レイヤー名の取得用(後々必要になるかもしれないので念のため作っておく) public string IsLayerNameObj(GameObject obj) { if (obj == null) { Debug.Log("オブジェクトが取得できていない"); return null; } return LayerMask.LayerToName(obj.layer); } //========================================================= //moveTimeの計算、スクリーン上の距離によって増減する。40は距離の目安 //========================================================= float moveTimeCalc(float dis, float moveTime) { if (dis >= 40) { moveTime = moveTime + dis / 150f; Debug.Log("計算した追加時間 = " + (dis / 150f)); } else { moveTime = dis / (dis * 2f); Debug.Log("計算した追加時間 = " + (dis / (dis * 2f))); } return moveTime; } }