【发布时间】:2016-03-22 17:44:05
【问题描述】:
我在 Unity (C#) 上为手机编写跑步游戏。
我使用 Canvas - Button 在屏幕上制作了暂停按钮。
我还在 Platformer2DUserControl 脚本中为 Pause 编写了代码。
这里是这个脚本的代码:
using UnityEngine;
using UnitySampleAssets.CrossPlatformInput;
namespace UnitySampleAssets._2D
{
[RequireComponent(typeof(PlatformerCharacter2D))]
public class Platformer2DUserControl : MonoBehaviour
{
private PlatformerCharacter2D character;
private bool jump;
public bool paused;
private void Awake()
{
character = GetComponent<PlatformerCharacter2D>();
paused = false;
}
private void Update()
{
/*if (Input.GetButton("Fire1"))
{
}*/
if (!jump)
// Read the jump input in Update so button presses aren't missed.
jump = Input.GetButton("Fire1"); //&& CrossPlatformInputManager.GetButtonDown("Jump");
}
private void FixedUpdate()
{
// Read the inputs.
bool crouch = Input.GetKey(KeyCode.LeftControl);
// float h = CrossPlatformInputManager.GetAxis("Horizontal");
// Pass all parameters to the character control script.
character.Move(1, false, jump);
jump = false;
}
public void Pause()
{
if (!jump)
// Read the jump input in Update so button presses aren't missed.
jump = Input.GetButton("Fire1"); //&& CrossPlatformInputManager.GetButtonDown("Jump");
paused = !paused;
if (paused)
{
jump = !jump;
Time.timeScale = 0;
}
else if (!paused)
{
// jump = Input.GetButton("Fire1");
Time.timeScale = 1;
}
}
}
}
我的暂停按钮运行良好。但是当我点击它时,我的角色正在跳跃并且游戏正在暂停。
我想做那个,当我点击按钮时游戏只是暂停并且角色不会跳跃。
我怎样才能做到。谢谢你的帮助。
【问题讨论】:
-
你真的,老实说,只是不能使用可笑的“时间刻度”技巧“暂停”统一游戏对上帝诚实。也就是说,老实说,只是不是他们在任天堂暂停游戏的方式。几年前有人在 Unity 论坛中提到的一个非常愚蠢的想法,它已在互联网上被复制。这完全是荒谬的。
-
游戏工程中的“暂停”是一种艺术形式。对于场景中的每一类对象,您必须特别为该类型的事物编写暂停代码。这是在游戏工程中实现暂停概念的唯一方法。
-
好的,我该如何暂停? @JoeBlow
-
@JoeBlow:我们在这里帮助他人。这里的基本规则之一是Be nice。荒谬,愚蠢,......这没有必要,也对某人没有帮助。
-
嗨@ЕвгенийСухомлин!你只需要为游戏中的每一件事写一个暂停函数。这是一项巨大的工作!如果你有一个机器人,写一个暂停函数。如果你有背景,写一个暂停函数,如果你有直升机,写一个暂停函数。这是一项艰巨的工作:O