我正在制作一个类似于karlson的游戏,并努力修复这一行代码来阻止错误。bug是格斗模式下的抓杀枪,而玩家没有按住鼠标按钮,我想做的代码是一个if语句,以检查bool是否为真,Input.GetMouseButtonUp是否正在发生。
***if ((bool)IsGrappling = true) && (Input.GetMouseButtonUp(0))){
StopGrapple;
}***这是代码
发布于 2022-05-10 16:08:41
if (IsGrappling == true && Input.GetMouseButtonUp(0))
{
StopGrapple;
}或
if (IsGrappling && Input.GetMouseButtonUp(0))
{
StopGrapple;
}发布于 2022-05-10 17:44:04
我在这里写了这三种代码的区别。
Input.GetMouseButton:只要按下键,就会连续执行该函数。
Input.GetMouseButtonDown:当你按下鼠标按钮时,只有第一帧。
Input.GetMouseButtonUp:当你释放鼠标按钮,只有第一帧。
!=和!运算符在c#中可以逆转这种情况。在这种情况下:
if (IsGrappling && !Input.GetMouseButton(0))
{
// do something
}https://stackoverflow.com/questions/72189363
复制相似问题