【发布时间】:2015-05-19 10:57:06
【问题描述】:
我浏览了整个互联网,但找不到解决问题的方法。我正在尝试创建一个游戏,它有 3 个场景:游戏开始、主要和游戏结束。
问题在于,当尝试从其他场景加载主关卡时,它并没有做它必须做的事情(例如跳跃)并且场景本身是滞后的。当我尝试仅加载主场景时,它可以正常工作,但是在角色死亡并重新加载场景后,它又开始滞后,我无法跳跃或做任何它应该做的事情。
对可能出现的问题有什么想法吗?
using UnityEngine;
using System;
public class Player : MonoBehaviour
{
// The force which is added when the player jumps
// This can be changed in the Inspector window
public Vector2 jumpForce = new Vector2(0, 300);
private bool shouldJump = true;
// Update is called once per frame
private float jumpThreshold = 0.5f;
private float previousJumpTime;
void FixedUpdate ()
{
// Jump
float mc = MicControl.loudness;
//Debug.Log (mc);
if (mc>1.3f && shouldJump)
{
shouldJump = false;
previousJumpTime = Time.time;
GetComponent<Rigidbody2D>().velocity = Vector2.zero;
GetComponent<Rigidbody2D>().AddForce(jumpForce);
}
if (!shouldJump)
{
if(Time.time-previousJumpTime>jumpThreshold)
{
shouldJump = true;
}
}
// Die by being off screen
Vector2 screenPosition = Camera.main.WorldToScreenPoint(transform.position);
if (screenPosition.y > Screen.height || screenPosition.y < 0)
{
Die();
}
}
// Die by collision
void OnCollisionEnter2D(Collision2D other)
{
Die();
}
void Die()
{
Application.LoadLevel ("main");
}
}
【问题讨论】:
-
我的猜测是它正在场景中加载脚本并且旧脚本和游戏对象没有被破坏。没有看到你的代码和你的场景就无法帮助你.....
-
我已经更新了帖子。请检查您是否有任何想法:)
-
很难说没有看到其余的脚本和场景的层次结构
标签: unity3d reload lag scene die