x


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

more ▼

asked Jul 09 '11 at 04:20 AM

Eli Davis gravatar image

Eli Davis
233 11 14 15

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

WOW. Alright. I'm dumb. All I had to do was create a folder named Resources. -_-

more ▼

answered Jul 09 '11 at 05:43 AM

Eli Davis gravatar image

Eli Davis
233 11 14 15

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1725
x352
x276
x223

asked: Jul 09 '11 at 04:20 AM

Seen: 2001 times

Last Updated: Jul 09 '11 at 05:43 AM