- Home /
Question by
graviton · Mar 15, 2015 at 07:16 PM ·
instantiatepositiongrid
Help, can't get Grid to instantiate in the center of the screen
I have a Grid I'm instantiating at (0, 0, 0), but the Grid seems to be appearing in the top right of the screen
The Grid script is attached to an Empty Game Object positioned at (0, 0, 0) and the camera is also positioned at (0, 0, 0)
I don't understand what's happening here
my script
using UnityEngine;
using System.Collections;
public class gridTest : MonoBehaviour
{
public int GridWidth;
public int GridHeight;
public GameObject myPrefab;
// Update is called once per frame
void Start ()
{
//Create Empty GameObject
GameObject newEmptyGameObject = new GameObject("Grid");
for(int y=GridHeight; y>=1; y--)
{
for(int x=GridWidth; x>=1; x--)
{
GameObject clone = Instantiate(myPrefab,new Vector3(x+x, y+y, 1),Quaternion.identity)as GameObject;
//Make clones Children of Grid
clone.transform.parent = newEmptyGameObject.transform;
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How to instantiate the prefabs on grid in Unity? 1 Answer
Need Help With 2D Array Grid Position Tracking With JavaScript 1 Answer
remove and replace item in grid 1 Answer
Not instantiating prefab in the right place after 2017 update 2 Answers
Keep instantiated GameObject's position while parenting it to another GameObject 3 Answers