【发布时间】:2020-05-18 14:44:54
【问题描述】:
我正在制作第一人称射击游戏,目前正在研究跳跃。我正在使用动画跳跃,因为我之前一直在与重力作斗争。但是,我的问题是,如果我的跳跃脚本和移动一样附加到播放器上,我的播放器将无法移动。但是我知道这与脚本无关,因为两个脚本都可以工作,但不能同时工作。
我相信这与动画有关。动画有 3 个部分,Base、Running 和 Jump。如果玩家正在移动,则跑步动画处于活动状态,如果玩家按下空格键,则跳跃动画处于活动状态。跳转动画优先。
玩家不能移动和跳跃有什么原因吗?
这里是代码和动画控制器:
动画和跳跃
public class Jump : MonoBehaviour
{
public bool run;
public float speed;
public GameObject player;
public Animator dgbanim;
public bool jump;
public float rejump;
public float rejumper;
// Start is called before the first frame update
void Start()
{
speed = 50;
run = false;
jump = false;
rejumper = 0;
rejump = 0;
}
// Update is called once per frame
void Update()
{
if (jump == false && Input.GetKey("space")) { dgbanim.SetBool("Jump", true); jump = true; rejump = 21; }
if (rejump > 0) { rejump = rejump - 1; }
if(rejump == 0) { jump = false; dgbanim.SetBool("Jump", false); }
if (Input.GetKey("w") || Input.GetKey("s") || Input.GetKey("a") || Input.GetKey("d") || Input.GetKey("up") || Input.GetKey("down") || Input.GetKey("left") || Input.GetKey("right")) { run = true; }
if (run == true) { dgbanim.SetBool("Running", true); run = false; }
else if (run == false) { dgbanim.SetBool("Running", false); }
}
private void OnCollisionEnter(Collision collision)
{
//if (collision.gameObject.tag != "EnemyBullets") { jump = true; rejump = 0; }
if (collision.gameObject.tag != "EnemyBullets") { jump = false; }
}
}
运动
public class Movement : MonoBehaviour
{
public GameObject player;
public float speed;
// Start is called before the first frame update
void Start()
{
speed = 50;
}
// Update is called once per frame
void Update()
{
player.transform.Translate(Input.GetAxis("Horizontal") * speed * Time.deltaTime, 0, Input.GetAxis("Vertical") * speed * Time.deltaTime);
}
}
【问题讨论】: