我已经找遍了互联网,但我还是找不到解决我的问题的办法。我正在尝试创建一个游戏,它有3个场景:游戏开始,主要和游戏结束。
问题是,当试图从其他场景加载主要关卡时,它不会做它必须做的事情(例如跳转)3D道具,并且场景本身是滞后的。当我尝试只加载主场景时,它可以正常工作unity重新加载场景,但在角色死后,场景重新加载后,它又开始滞后unity重新加载场景游戏素材,我无法跳转或做任何它应该做的事情。
你知道问题出在哪里吗?
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().velocity = Vector2.zero;
GetComponent().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");
}
}
复制
文章来源:https://cloud.tencent.com/developer/ask/sof/101709482/answer/103764358