【发布时间】:2020-06-15 07:27:52
【问题描述】:
所以,我正在制作一个游戏,其中一个玩家通过按下 shift 来改变对两个角色的控制,所以,当按下 shift 时,玩家 1 的移动被禁用并且玩家 2 脚本被启用,我通过使移动速度和跳跃达到数字为零,但是当按下shift时没有任何反应,我该怎么做才能解决这个问题?
顺便说一下,我将Fire2设置为“shift”以澄清,并且还关注“CanPlay”变量,因为这是我认为问题所在。
代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class movimento : MonoBehaviour
{
public bool CanPlay;
void Update()
{
float h = Input.GetAxisRaw("Horizontal");
float speedY = PlayerRB.velocity.y;
PlayerRB.velocity = new Vector2(h * speed, speedY);
if (Input.GetButtonDown("Jump") && Isgrounded == true)
{
PlayerRB.AddForce(new Vector2(0, jumpforce));
}
if (h > 0 && IsLookLeft == true)
{
Flip();
}
else if (h < 0 && IsLookLeft == false)
{
Flip();
}
if (CanPlay = false)
{
speed = 0f;
jumpforce = 0f;
}
if (CanPlay = true)
{
speed = 10f;
jumpforce = 150f;
}
if (Input.GetKeyDown("Fire2"))
{
CanPlay = !CanPlay;
}
}
}
【问题讨论】: