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 () {
}