【发布时间】:2023-03-24 08:26:01
【问题描述】:
每当我运行我的游戏时,它都会冻结,但如果没有这个 C# 脚本,它就不会。
我尝试更改我的代码,它在 Unity 之外的 .NET 中工作(对某些功能进行了一些调整),但是当它在 Unity 中时它会崩溃。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Throw : MonoBehaviour
{
public Rigidbody rb;
string final = "final:";
public float force = 1;
public float accuracy = 0;
void incto(float amount)
{
while (force < amount)
{
Debug.Log(force);
force++;
}
}
void decto(float amount)
{
while (force > amount)
{
Debug.Log(force);
force--;
}
}
void fstart()
{
while (true)
{
force = 1;
incto(200);
decto(1);
if(Input.GetKey(KeyCode.E))
{
Debug.Log(final + force);
break;
}
}
}
// Start is called before the first frame update
void Start()
{
fstart();
}
// Update is called once per frame
void FixedUpdate()
{
Debug.Log(force);
}
}
它应该减少和增加力值,然后按 E 时停止,但 Unity 只是崩溃。
【问题讨论】: