I have a complicated issue. Here is some of my code, which is a class for game tiles.
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
namespace game_tiles {
public class GameTile {
public GameObject tilePrefab;
public bool isPassable;
public float moveCost;
}
public class GameTiles : MonoBehaviour {
public GameTile redTile;
public GameObject redTilePrefab;
public bool redTileIsPassable;
public float redTileMoveCost;
public void Main() {
GameTile redTile = new GameTile();
redTile.tilePrefab = redTilePrefab;
redTile.isPassable = redTileIsPassable;
redTile.moveCost = redTileMoveCost;
print(redTile);
}
}
}
When the above code runs, it prints to the unity console: game_tiles.GameTile
Completely normal, right?
However, I want to use the code in a different file, using this code here:
using UnityEngine;
using System.Collections.Generic;
using game_tiles;
namespace board_manager {
public class BoardManager : MonoBehaviour {
GameTiles gameTiles;
// Use this for initialization
void Start() {
gameTiles = GameObject.Find("Game Tile Class").GetComponent<GameTiles>();
GameTile redTile = gameTiles.redTile;
print(redTile);
}
}
}
This code, for some reason, prints Null to the Unity console, and, thus, I cannot use any of the variables in the redTile object. How can I get both programs to print game_tiles.GameTile? Thank you for any help.
P.S. Sorry about all of the similar gameTile variables. I could not think of different names. d=