Unity3d 关于Unity代码的问题(可以为PC而不是移动设备构建)
我正在设计一个基于Unity的2D平台,我想把它部署到我的手机上 然而,当我尝试构建并运行到我的Android设备时,我总是会出错 这是我的代码:Unity3d 关于Unity代码的问题(可以为PC而不是移动设备构建),unity3d,mobile,Unity3d,Mobile,我正在设计一个基于Unity的2D平台,我想把它部署到我的手机上 然而,当我尝试构建并运行到我的Android设备时,我总是会出错 这是我的代码: public class PlayerControl : MonoBehaviour { private Rigidbody2D rb; // Start is called before the first frame update void Start() { rb = GetComponent&
public class PlayerControl : MonoBehaviour
{
private Rigidbody2D rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
rb.velocity = new Vector2(5, rb.velocity.y);
if (Input.GetMouseButtonDown(0)){
rb.velocity = new Vector2(5, 8);
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.name == "Win")
{
UnityEditor.EditorApplication.isPlaying = false;
Application.Quit();
}
if (collision.gameObject.name == "Lose")
{
SceneManager.LoadScene(0);
}
}
}
公共类玩家控制:单一行为
{
私有刚体2d rb;
//在第一帧更新之前调用Start
void Start()
{
rb=GetComponent();
}
//每帧调用一次更新
无效更新()
{
rb.velocity=新矢量2(5,rb.velocity.y);
if(Input.GetMouseButtonDown(0)){
rb.velocity=新矢量2(5,8);
}
}
私有无效OnTiggerEnter2D(已碰撞R2D碰撞)
{
如果(collision.gameObject.name==“Win”)
{
UnityEditor.EditorApplication.isplay=false;
Application.Quit();
}
如果(collision.gameObject.name==“Lose”)
{
场景管理器。加载场景(0);
}
}
}
在我添加OnTiggerEnter2D()之前,游戏可以在我的Android fine上构建和运行。添加后,出现了错误
我怀疑这可能与EditorApplication有关。isPlaying=false?还有可能是SceneManager.LoadScene()
我可以使用其他代码吗
我希望游戏在我赢的时候结束,在我输的时候“重新开始”。你的问题伴随着这句话:
UnityEditor.EditorApplication.isPlaying = false;
不能在生成中包含UnityEditor.dll。您还应该确保您没有在名称空间中使用它
或者,您可以使用预处理器对其进行封装
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#endif
错误消息是什么?