2
我试图找到一种方法来暂停我的游戏在Unity中,而不使用“Time.timeScale = 0;”。我想改变这一点的原因是我想让角色在游戏暂停时播放动画。有没有办法改变这个脚本,以便在玩家点击空间之后,重力和前进速度只能“设置”?还是有更好的方法来解决这个问题?暂停Unity游戏没有“Time.timeScale = 0”
这是脚本:
public class PlayerMove : MonoBehaviour {
Vector3 velocity = Vector3.zero;
public Vector3 gravity;
public Vector3 FlyVelocity;
public float maxSpeed = 5f;
public float forwardSpeed = 1f;
bool didFly = false;
bool dead = false;
float deathCooldown;
Animator animator;
// Use this for initialization
void Start() {
animator = GetComponentInChildren<Animator>();
}
// Do Graphic & Input updates here
void Update(){
if (dead) {
deathCooldown -= Time.deltaTime;
if (deathCooldown <= 0) {
if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0)) {
Application.LoadLevel(Application.loadedLevel);
}
}
}
if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0)) {
didFly = true;
animator.SetTrigger ("DoFly");
}
}
void OnCollisionEnter2D(Collision2D collision) {
animator.SetTrigger ("Death");
dead = true;
}
// Do physics engine updates here
void FixedUpdate() {
if (dead)
return;
velocity += gravity * Time.deltaTime;
velocity.x = forwardSpeed;
if(didFly == true) {
didFly = false;
velocity += FlyVelocity;
}
velocity = Vector3.ClampMagnitude(velocity, maxSpeed);
transform.position += velocity * Time.deltaTime;
deathCooldown = 0.5f;
}
}
您可以在gamedev.stackexchange.com找到更多有关统一的帮助 – Sayse 2014-09-04 08:27:21
没有任何内容可以为此而统一。但是我建议看一看状态机,因为当你有不同的状态时(例如暂停/播放)以及当进入/退出状态时需要完成的事情时,它们会提供帮助。 – Imapler 2014-09-04 08:28:07
我知道这个线程有点旧,但你可以在这里试试我的答案:http://stackoverflow.com/questions/31718168/pausing-in-unity/31718377#31718377 – NeverHopeless 2015-07-31 11:57:56