- Home /
Loading Prefab from Script
OMMMGGGGG Whats happening.
Alright. So I've made a ship factory. When called upon it should make a ship. Everything is working fine. Until it comes to the actual Instantiating. I'm trying to get a prefab from my projects pane through scripting it, and not manualy defining it as a variable at the top and then dragging and dropping it. So at the moment, the Unitys telling me to insert a semicolen at line 17 (line defining PTBoat var), which I have. Am I doing something wrong? (well I obvously am) but can anyone point to the problem. So heres the code I've used.
public class ShipFactory {
function newShip(type : ShipType, location) {
if( !type ) {
// TODO: return blank ship, debug statement
return null;
}
var ship = null;
if( type.Equals(ShipType.PT) ) {
var PTBoat = (GameObject)Resources.Load("Easy Boat");
if(PTBoat!=null ) {
ship = UnityEngine.Object.Instantiate(PTBoat, location, Quaternion.identity);
} else {
Debug.Log("PTBoat prefab is null");
}
}
return ship;
}
}
Also I called the class using this:
shipFactory.newShip(ShipType.PT, ShipSpotA);
Incase that would help at all. If you need anymore detail please just ask. I've been stressing over this for like an hour
Answer by Eli-Davis · Jul 09, 2011 at 05:43 AM
WOW. Alright. I'm dumb. All I had to do was create a folder named Resources. -_-