次のような TouchDetector.cs というタイトルの C# スクリプトが 1 つあります。
using UnityEngine;
using System.Collections;
public class TouchDetector : MonoBehaviour
{
public delegate void deTouchEvent (enTouchType touchType);
public static event deTouchEvent evTouchEvent;
public enum enTouchType
{
SwipeLeft,
SwipeRight,
SwipeDown,
SwipeUp,
}
void Start ()
{
}
void Update ()
{
if (evTouchEvent == null)
return;
if (Input.GetKeyDown(KeyCode.UpArrow )) evTouchEvent(enTouchType.SwipeUp );
if (Input.GetKeyDown(KeyCode.DownArrow )) evTouchEvent(enTouchType.SwipeDown );
if (Input.GetKeyDown(KeyCode.LeftArrow )) evTouchEvent(enTouchType.SwipeLeft );
if (Input.GetKeyDown(KeyCode.RightArrow)) evTouchEvent(enTouchType.SwipeRight);
if (Input.touchCount > 0)
{
foreach (Touch t in Input.touches)
{
Vector3 swipe = t.deltaPosition * t.deltaTime;
if (swipe.y > 0.5f) evTouchEvent(enTouchType.SwipeUp );
if (swipe.y < -0.5f) evTouchEvent(enTouchType.SwipeDown );
if (swipe.x > 0.5f) evTouchEvent(enTouchType.SwipeRight);
if (swipe.x < -0.5f) evTouchEvent(enTouchType.SwipeLeft );
}
}
}
}
次のキーコード呼び出しを、上記の対応するスワイプ呼び出しに置き換えようとしています。私はプログラミングに少し慣れていないので、ここで独学しようとしています。私はなんとかスワイプスクリプトを機能させることができましたが、それが理にかなっている場合、これをコントローラーとして取得する方法まで、あらゆる手段を使い果たしました。あなたが私に与えることができる助けやアドバイスをありがとう. 私は次のことを試しました。
if(SwipeLeft)
{
//Do something here
}
しかし、これは私にとってはうまくいきません。他の制御スクリプト内で制御タイプを参照できないようです。置き換えようとしている Control.cs スクリプトのスクリプトは次のようになります。
if (Input.GetKeyDown(KeyCode.LeftArrow) && m_playerJump <= -1.0f && m_playerSlide <=0.0f)
{
if (m_playerDirection == enCellDir.North) m_playerNextDirection = enCellDir.West;
if (m_playerDirection == enCellDir.East ) m_playerNextDirection = enCellDir.North;
if (m_playerDirection == enCellDir.South) m_playerNextDirection = enCellDir.East;
if (m_playerDirection == enCellDir.West ) m_playerNextDirection = enCellDir.South;
}
Input.GetKeyDown の代わりに、SwipeLeft と言うか、コーディングする必要があります。助けてください。私はとてもイライラしています。列挙型を調べましたが、何を読んでいるのか、またはそれらを参照する方法がよくわかりません。私が読んだことから、enumはJavaのintに似ていると思います。しかし、もしそうなら、私はそれらをどのように呼びますか?