For Loop (C#)
迴圈
Last updated
迴圈
Last updated
using UnityEngine;
public class GameManager : MonoBehaviour
{
public GameObject SpherePrefab;
void Start()
{
float length = 1.5f;
int count = 5;
for (int j = 0; j < count; j++)
{
for (int i = 0; i < count; i++)
{
GameObject go = Instantiate(SpherePrefab);
go.transform.position = new Vector3(i * length - count / 2 * length,0 ,j * length - count / 2 * length);
}
}
}
}
試著修改劃紅線的程式碼,去解以下題目。
using UnityEngine;
public class GameManager : MonoBehaviour
{
public GameObject SpherePrefab;
void Start()
{
float length = 1.5f;
int count = 5;
for (int j = 0; j < count; j++)
{
for (int i = 0; i <= j; i++)
{
GameObject go = Instantiate(SpherePrefab);
go.transform.position = new Vector3(i * length - count / 2 * length,0 ,j * length - count / 2 * length);
}
}
}
}