我在此處使用此代碼並在該行下生成循環中的對象,並且在我的心臟中每次都會在循環中產生對象--GameobjectTempVec3 - .5316515f它循環。向量3只會在for循環中首次運行時更改x,但不會在下一次運行
問題
它確實改變了寶貴的運行在它上面的for循環的第一次。但是下一次不會改變x,但它會再次生成對象,現在在剛生成的對象中。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameUIManager : MonoBehaviour
{
public float heartGameobjectX;
public float heartGameobjectY;
public float heartGameobjectZ;
public int scoreCount;
public int lives;
public int liveCount;
public int dogsEscaped;
public GameObject[] spawnebleObjects;
public GameObject heartGameobject;
// Use this for initialization
void Start()
{
Vector3 heartGameobjectTempVec3 = new Vector3(heartGameobjectX, heartGameobjectY, heartGameobjectZ);
Instantiate(heartGameobject, heartGameobjectTempVec3, transform.rotation);
liveCount--;
for (int i = 1; i <= liveCount; i++)
{
heartGameobjectTempVec3[0] = -.5316515f;
Instantiate(heartGameobject, heartGameobjectTempVec3, transform.rotation);
}
}
}
Instantiate返回原始對象hearGameObject的一個副本,你需要將它存儲在任何地方嗎?我不知道團結,但我會假設你必須告訴團結才能展示物體或某物。 –
您正在使用「開始」而不是「更新」。 '開始'將運行一次。另外,正如@Evgenii所說的,你直接設置值,而不是遞增或遞減。 –