我的代码的这一部分应该生成一行图像,我保存为表示为网格,我对 unity 和 id 很陌生,喜欢一些关于为什么此代码不起作用的帮助。我这段代码的目的是每当使用“AddRow”过程时生成行。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity.Properties;
using UnityEngine;
using UnityEngine.SocialPlatforms.GameCenter;
namespace Assets
{
public class GridGen : MonoBehaviour
{
// list to keep track of which row has already been generated
private List<bool> boolList = new List<bool>();
private int width = 7;
private float tileSize = 1;
// made to clear bool list and generated blocks when game restarts
public void Restart()
{
}
public void AddRow(char material, int row)
{
GameObject referencetile;
if (material == 'g')
{
referencetile = (GameObject)Instantiate(Resources.Load("grass"));
//gets grass block image
}
else
{
referencetile = (GameObject)Instantiate(Resources.Load("Road"));
//gets road image
}
for (int i = 0; i < width; i++)
{
GameObject tile = (GameObject)Instantiate(referencetile, transform);
float posY = row * tileSize;
float posX = (i - 3) * tileSize;
tile.transform.position = new Vector2(posX, posY);
}
Destroy(referencetile);
}
}
}```
i used chat gbt to try find the problem but they only said that i may of typed the wrong value for the names of the pictures
我猜您可能面临一个甚至两个问题: