【发布时间】:2016-05-31 19:01:46
【问题描述】:
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float speed = 80.0f; // Code for how fast the ball can move. Also it will be public so we can change it inside of Unity itself.
private Rigidbody rb; // Variable that applies itself to Ball
void Start()
{
rb = GetComponent<Rigidbody> ();
}
// Code That enables our Player to move around.
void Movement()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
}
// Update is called once per frame
void Update ()
{
Movement ();
}
【问题讨论】:
-
我想将代码实现到 Start 方法中。
-
如果你解释你想要做什么并且解释得很好,也许有人可以理解你的问题并帮助你。什么输入?
-
输入将是使其移动的键盘键。我有两个玩家对象,但我每个玩家都有不同的键来让它移动
-
好的。现在说得通了。还有许多其他方法可以在没有 id 或创建另一个类的情况下做到这一点。用播放器一的代码和播放器 2 的代码更新您的问题,我将尝试提供一种方法来做到这一点。
-
我已经编辑好了