为什么我的脚本精灵适用于磁砖图?(Unity2D)



我正试图制作一个简单的自上而下2d移动演示作为个人项目,我遇到了一个非常奇怪的障碍。我使用这个网站上的代码来移动精灵,效果很好。然后我使用tilemap绘制了一个简单的结构来测试精灵的移动和碰撞,但现在当我使用箭头键时,它会以反向控制方案移动我用tilemap绘制的结构(向上箭头是向下的,向左箭头是向右的,等等)。下面是我为测试精灵编写的脚本。有人能帮忙吗?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class PlayerController : MonoBehaviour
{
Rigidbody2D body;
float horizontal;
float vertical;
Vector2 move;
public float runSpeed = 2.5f;
void Start()
{
body = GetComponent<Rigidbody2D>();
}
void Update ()
{
horizontal = Input.GetAxis("Horizontal");
vertical = Input.GetAxis("Vertical"); 
//move.x = horizontal;
//move.y = vertical;
}
private void FixedUpdate()
{  
body.velocity = new Vector2(horizontal * runSpeed, vertical * runSpeed);
}
}

我知道情况更糟,但你能试试吗?:)

body.velocity = new Vector2(-horizontal * runSpeed, -vertical * runSpeed);

相关内容

最新更新