The problem is that i cant get a read from array items in my stepping stone script.
The code where the array items is in:
//Bag.js
var numberOfSlots=24;
var numberOfColumns=4;
var textureSize=64;
var showBag=true;
public var items : Item[];
private var windowRect: Rect;
function Start(){
var slots : float=numberOfSlots;
var cols : float=numberOfColumns;
items=new Item[numberOfSlots];
var rows=Mathf.Ceil(slots / cols);
var width = textureSize * numberOfColumns + 20;
var height = textureSize * rows + 30;
windowRect = Rect((Screen.width - width) / 2, (Screen.height - height) / 2, width, height);
}
function Update(){
if(Input.GetKeyDown("b")) showBag=!showBag;
//logic code here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
}
public function check(oName:String)
{
for(var i = 0; i < items.length; i++)
{
if(items*)*
{
if(items*.name == oName)*
{
return true;
}else{
return false;
}
}
}
}
function OnGUI(){
* if(showBag){*
* GUI.depth = 0;*
* CreateWindow();*
* }*
}
function DragInventory(windowID:int){
* for(var i=0; i< numberOfSlots; i++){*
* var y=Mathf.Floor(i / numberOfColumns);*
_ var x=i - y * numberOfColumns;
var rect = Rect(textureSize * x + 10, textureSize * y + 20, textureSize, textureSize);
* var texture : Texture2D;*
if(items)texture = items*.texture;
var slot = GUI.Button(rect, texture);*_
* if(rect.Contains(Event.current.mousePosition)){*
_ if(items == null && DragDrop.item != null && Input.GetMouseButtonUp(0)){
items = DragDrop.item;
if(items*.gameObject){
Destroy(items.gameObject);
items.gameObject=null;
}
}*_
_ if(Input.GetMouseButtonUp(1) && items && DragDrop.toolSelected){
* var go=new GameObject.CreatePrimitive(PrimitiveType.Cube);
go.renderer.material.mainTexture=items.texture;
go.AddComponent(Rigidbody);
go.AddComponent(AddToInventory);
var s=go.GetComponent(AddToInventory);
s.item=items;
//items = null;
DragDrop.toolSelected=false;
}*_
* if(slot){}*
* }*
* }*
GUI.DragWindow();
}
function AddItem(item : Item){
* for(var i=0; i< numberOfSlots; i++){*
_ if(!items*){
items=item;
if(item.gameObject)Destroy(item.gameObject);
return;
}
}
}*_
function CreateWindow()
{
* GUI.BeginGroup(windowRect);*
* windowRect = GUI.Window(0, windowRect, DragInventory, “Inventory”);*
* GUI.EndGroup();*
}
the script that calls the items array
var fps;
*function OnTriggerEnter () { *
fps = GameObject.Find(“First Person Controller”);
if(fps == true);
Debug.Log(“fps gevonden”);
var bag = GetComponent(Bag);
if(bag == true);
Debug.Log(“bag gevonden”);
var item = bag.items;
//some code to find things in the array
And the error i get :(NullReferenceException: Object reference not set to an instance of an object
steppingstone1.OnTriggerEnter () (at Assets/steppingstone1.js:10))
All help is welcome.
And to anyone who helps thankyou