I’m having a bit of difficulty figuring this out, but I think I am overlooking something simple.
I had my script for a level generator which would instantiate prefabs to build the level. It followed this pattern, just in the root of the .js file which I attached to a blank object in the scene.
public var wall : Transform;
function Start () {
for (var x = 0; x < 10; x++){
var newTile : Transform;
newTile = wall;
var instTile : Transform = Instantiate(newTile, Vector3(x, 0,0),Quaternion.identity);
}
}
At which point I drag the prefab onto the script variables area in the Inspector.
However, I want to create a class that will do the instantiating. I know that I need to use GameObject.Instantiate, but my issue comes from not having the Prefabs available within the class.
If I create a class and try to access the prefabs, it says it cannot recognize the prefabs.
Here is an example of what I was trying using classes:
public var wall : Transform;
class area{
function area(){
var newTile : Transform;
newTile = wall;
var instTile : Transform = GameObject.Instantiate(newTile, Vector3(x, 0,0),Quaternion.identity);
}
}
function start(){
var currentZone = new area();
}
Which tells me that there is no such object as “wall”. If I declare the prefabs within the class, I can no longer drag them onto the script in the Inspector Panel.
Am I missing something obvious here?