How do you Instantiate a Prefab and call its instance variable?

I want to be able to create an instance of a prefab and then call its instance variable.
I’m confused because I’m seeing multiple ways of doing it and I can’t get any working.

Both prefab’s exist in my resources directory, they player exists on the scene, the
ship does not since I’m trying to create it from scratch.

I’ve seen with Resources, GameObject.Find and just calling the variable.
In all cases I get an error saying the prefab doesn’t exist or etc…

Current Error

Assets/scripts/player.js(7,18): BCE0019: 'hull' is not a member of 'UnityEngine.GameObject'. 

Assets/Resources/player.js

var ship : GameObject;

function Start () {
  ship = Instantiate(Resources.Load('ship'));
  Debug.Log(ship.hull);
}

function Update () {

}

Assets/Resources/ship.js

public var hull    : int = 50;
public var scrap   : int = 30;
public var shields : int = 1;
public var fuel    : int = 16;
public var missles : int = 8;
public var drones  : int = 0;
public var oxygen  : int = 100;
public var crew = [];

function Start () {
}

function Update () {

}

Your problem is that Instantiate returns a GameObject and your variable is connected to that game object through the ship script, but they aren’t actually the same object. You have to get the ship script using GetComponent. I’d advise following the naming convention and calling your scripts names that start with a capital letter (it makes reading and understanding code much easier when you can distinguish classes/scripts from variables).

Anyway:

  var shipComponent = ship.GetComponent(ship);  //The second ship is the name of the class/script the first one is the game object you instantiated.
  shipComponent.hull  = whatever;