Question by
Philosophbot · Apr 20, 2018 at 05:23 PM ·
c#2d gameinstantiate prefabinstantiation
Having trouble instantiating prefabs in my 2D game
I'm currently making a 2D open world game and made multiple block prefabs for the different types of terrain I am adding to my game. What I am trying to do is make a script that will allow me to instantiate squares of any of these block prefabs of my choosing. However, for whatever reason, my script doesn't seem to work and any solutions I've already looked at online seem to basically do what I've already done.
I have the script attached to an empty gameManager object, here is the code: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class TerrainCreator : MonoBehaviour {
public GameObject torchBlock;
public GameObject Block;
public int rows;
public int columns;
public float x;
public float y;
public float z;
public float xSpacing;
public float ySpacing;
public bool torches;
// Use this for initialization
void Start () {
for (int r = 0; r == rows; r++) {
for (int c = 0; c == columns; c++) {
Vector3 pos = new Vector3 (x + (c * xSpacing), y - (r * ySpacing), z);
Instantiate (Block, pos, Quaternion.identity);
}
}
}
// Update is called once per frame
void Update () {
}
}
Comment
Best Answer
Answer by Philosophbot · Apr 20, 2018 at 05:27 PM
Actually I fixed it by changing the equal sign to a less than sign :l