我是 C# 统一的初学者。add force
我正在寻找用in交换立方体的解决方案8 direction
,但我找不到任何东西。我真的很困惑,我该怎么做。有人请在这方面指导我。任何用于解决问题的代码示例或教程将不胜感激。
提前致谢。这是我的代码:
using UnityEngine;
using System.Collections;
public class Swaping1 : MonoBehaviour {
int swipeIndex = -1; //index of first detected swipe to prevent multiple swipes
public Vector2 startPos; //starting position of touch
public float minSwipeDist;
public float UpSwape;
public float DownSwape;
public float LeftSwape;
public float RightSwape;
public GUIButtons GUIButtonsObj;
// Use this for initialization
void Start () {
GUIButtonsObj=GetComponent<GUIButtons>();
}
public void swipe()
{
for (int i = 0; i < Input.touchCount; i++) {
Touch touch = Input.touches [i];
switch (touch.phase) {
case TouchPhase.Began:
if (swipeIndex == -1) {
swipeIndex = i;
startPos = touch.position;
}
break;
case TouchPhase.Moved:
if (i != swipeIndex)
break;
Vector2 direction = touch.position - startPos;
//vertical swipe
if (Mathf.Abs (direction.x) < Mathf.Abs (direction.y)) {
//swipe up
if ((touch.position.y - startPos.y) > minSwipeDist) {
//GUIButtonsObj.UpButton();
//transform.Translate(0f, UpSwape, 0f);
swipeIndex = -1;
}
//swipe down
else if ((touch.position.y - startPos.y) < -minSwipeDist) {
//transform.Translate(0f, -DownSwape, 0f);
//GUIButtonsObj.DownButton();
swipeIndex = -1;
}
}
//horizontal swipe
else {
//swipe right
if ((touch.position.x - startPos.x) < -minSwipeDist) {
//transform.Translate(-RightSwape, 0f, 0f);
GUIButtonsObj.LeftButton();
swipeIndex = -1;
}
//swipe left
else if ((touch.position.x - startPos.x) > minSwipeDist) {
// transform.Translate(LeftSwape, 0f, 0f);
GUIButtonsObj.RightButton();
swipeIndex = -1;
}
}
break;
}
}
}
// Update is called once per frame
void Update ()
{
swipe ();
}
}