Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#手机游戏运动_C#_Android_Mobile_Input - Fatal编程技术网

C#手机游戏运动

C#手机游戏运动,c#,android,mobile,input,C#,Android,Mobile,Input,因此,为了进一步了解手机游戏开发,我使用C#/Unity编写了一个简单的snake游戏。我一直很难在移动(android)设备上正常工作,到目前为止,这是使用键盘在Unity中播放时的代码。我将如何将此代码转换为类似的方式,但在用户在手机屏幕上滑动或轻敲输入的移动设备上工作 void Movement() { GameObject temp; nexPos = head.transform.position; switch (NESW) { ca

因此,为了进一步了解手机游戏开发,我使用C#/Unity编写了一个简单的snake游戏。我一直很难在移动(android)设备上正常工作,到目前为止,这是使用键盘在Unity中播放时的代码。我将如何将此代码转换为类似的方式,但在用户在手机屏幕上滑动或轻敲输入的移动设备上工作

 void Movement()
{
    GameObject temp;
    nexPos = head.transform.position;
    switch (NESW)
    {
        case 0:
            nexPos = new Vector2(nexPos.x, nexPos.y + 1);
            break;
        case 1:
            nexPos = new Vector2(nexPos.x + 1, nexPos.y);
            break;
        case 2:
            nexPos = new Vector2(nexPos.x, nexPos.y - 1);
            break;
        case 3:
            nexPos = new Vector2(nexPos.x - 1, nexPos.y);
            break;
    }
    temp = (GameObject)Instantiate(snakePrefab, nexPos, transform.rotation);
    head.Setnext(temp.GetComponent<Snake>());
    head = temp.GetComponent<Snake>();

    return;
}

void changeDirection()
 {
    if (NESW != 2 && Input.GetKeyDown(KeyCode.W))
    {
        NESW = 0;
    }
    if (NESW != 3 && Input.GetKeyDown(KeyCode.D))
    {
        NESW = 1;
    }
    if (NESW != 0 && Input.GetKeyDown(KeyCode.S))
    {
        NESW = 2;
    }
    if (NESW != 4 && Input.GetKeyDown(KeyCode.A))
    {
        NESW = 3;
    }
}
void移动()
{
游戏对象温度;
nexPos=head.transform.position;
开关(NESW)
{
案例0:
nexPos=新矢量2(nexPos.x,nexPos.y+1);
打破
案例1:
nexPos=新向量2(nexPos.x+1,nexPos.y);
打破
案例2:
nexPos=新向量2(nexPos.x,nexPos.y-1);
打破
案例3:
nexPos=新向量2(nexPos.x-1,nexPos.y);
打破
}
temp=(游戏对象)实例化(蛇预制、nexPos、transform.rotation);
Setnext(temp.GetComponent());
head=温度GetComponent();
返回;
}
void changeDirection()
{
if(NESW!=2&&Input.GetKeyDown(KeyCode.W))
{
NESW=0;
}
if(NESW!=3&&Input.GetKeyDown(KeyCode.D))
{
NESW=1;
}
if(NESW!=0&&Input.GetKeyDown(KeyCode.S))
{
NESW=2;
}
if(NESW!=4&&Input.GetKeyDown(KeyCode.A))
{
NESW=3;
}
}

对于android,请看这个答案:它帮助我更好地理解了这个问题,但我仍然无法使用visual studio在C语言中正确地编写它。对于android,请看这个答案:它帮助我更好地理解了这个问题,但我仍然无法使用visual studio在C语言中正确地编写它。