I’m trying to make a tactics based RPG along the same vein as Final Fantasy Tactics and I found a great scrip that works well for my purposes. Unfortunately, I don’t really understand it very well and I’ve been trying to fiddle with it so that I can learn how it functions. It takes a prefab object and tiles it together. When I tried to make the prefab twice the size, it still places them the same distance apart as before, making them overlap. Is there anywhere in the code I can fix this? Can anyone help me understand what in the world is going on in here?
From my manager script:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Manager : MonoBehaviour {
public GameObject TilePrefab;
public int mapSize = 11;
List <List> map = new List<List>();
// Use this for initialization
void Start () {
generateMap ();
}
// Update is called once per frame
void Update () {
}
void generateMap(){
map = new List<List> ();
for (int i = 0; i < mapSize; i++) { //This loop will run until i=mapSize, adding one each time. i is given the value 0, then used just to tell the loop when to stop.
List row = new List ();
for (int j = 0; j < mapSize; j++) {
Tile tile = ((GameObject)Instantiate (TilePrefab, new Vector3 (i - Mathf.Floor (mapSize / 2), 0, -j + Mathf.Floor (mapSize / 2)), Quaternion.Euler (new Vector3 ()))).GetComponent ();
tile.gridPosition = new Vector2 (i, j);
row.Add (tile);
}
map.Add (row);
}
}
}
In my tile script:
using UnityEngine;
using System.Collections;
public class Tile : MonoBehaviour {
public Vector2 gridPosition = Vector2.zero;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnMouseEnter(){
transform.renderer.material.color = Color.blue;
Debug.Log (“my position is (” + gridPosition.x + “,” + gridPosition.y);
}
void OnMouseExit(){
transform.renderer.material.color = Color.white;
}
}