对象连续克隆c# unity
本文关键字:unity 连续 对象 | 更新日期: 2023-09-27 17:51:22
你好,我已经创建了一个系统,找到一个特定的模型并生成它,但是它会有意识地一遍又一遍地克隆对象,尽管我试图找到结束函数的方法或False不工作的bool,任何关于如何做到这一点的建议将是伟大的。感谢您的宝贵时间和耐心。
void Update()
{
if (NKCell.GetComponent<ModelChangeScript>().HighqualityModel == true )
{
HQModelSpawn();
public void HQModelSpawn()
{
HighQualityModel = false;
Transform[] HQTransforms = this.GetComponentsInChildren<Transform>();
foreach (Transform t in HQTransforms)
{
if (t.gameObject.CompareTag("HighQualityModel"))
{
HQMesh = t.gameObject;
Instantiate(t.gameObject, CurrentPosition, Currentrotation);
transform.position = CurrentPosition;
transform.rotation = Currentrotation;
Debug.Log("Found " + t);
break;
}
}
}
首先,你需要在Start Event中这样做,如果你不愿意这样做,那么更新的代码如下,你应该false bool也如下面的代码所建议的。
void Update()
{
if (NKCell.GetComponent<ModelChangeScript>().HighqualityModel == true )
{
HQModelSpawn();
NKCell.GetComponent<ModelChangeScript>().HighqualityModel = false;
}
public void HQModelSpawn()
{
HighQualityModel = false;
Transform[] HQTransforms = this.GetComponentsInChildren<Transform>();
foreach (Transform t in HQTransforms)
{
if (t.gameObject.CompareTag("HighQualityModel"))
{
HQMesh = t.gameObject;
Instantiate(t.gameObject, CurrentPosition, Currentrotation);
transform.position = CurrentPosition;
transform.rotation = Currentrotation;
Debug.Log("Found " + t);
break;
}
}
}