x


Picking up things for your inventory...

Hi everyone... I found this AMAZING (considering it was free) inventory system, and I'm trying to make it so I can select things with the crosshair, as apposed to the mouse. I've tried everything, and I know I'm going to have to use some kind of raycast, but I'm just terrible with that kind of stuff. If someone could help me, here's my script for the item to pick up:

var inventoryIcon:Texture2D;
var canGet=true;
var itemType:String;
var BoneList:Transform[];
var stackable=false;
var maxStack=99;
var stack=1;
var isEquipment=true;

function Awake(){
    var Bones=GetComponentsInChildren(Transform);
    var newarray=new Array(Bones);
    BoneList=newarray.ToBuiltin(Transform);
}

function OnMouseDown(){
    var getit=true;
    var playersinv=FindObjectOfType(Inventory);

    if(canGet){
       if(stackable){
         var locatedit:Item;
         for(var t:Transform in playersinv.Contents){
          if(t.name==this.transform.name){
              var i:Item=t.GetComponent(Item);
              if(i.stack<i.maxStack){
                 locatedit=i;
              }
          }
         }
         if(locatedit!=null){
          getit=false;
          locatedit.stack+=1;
          Destroy(this.gameObject);
         }
         else{
          getit=true;
         }
       }
       if(getit){
         playersinv.AddItem(this.transform);
         MoveMeToThePlayer(playersinv.transform);
       }
    }
}

function MoveMeToThePlayer(theplayer:Transform){

    canGet=false;
    transform.collider.isTrigger=true;
    var renderers=GetComponentsInChildren(Renderer);
    for(var rend:Renderer in renderers){
       rend.enabled=false;
    }
    if(transform.renderer!=null){
       transform.renderer.enabled=false;
    }
    transform.parent=theplayer;.
    transform.localPosition=Vector3.zero;

}

------------- And here's my inventory script:

------------- var Contents:Transform[];

function AddItem(Item:Transform){
    var newContents=new Array(Contents);
    newContents.Add(Item);
    Debug.Log(Item.name+" Has been added to inventroy");
    Contents=newContents.ToBuiltin(Transform);
}

function RemoveItem(Item:Transform){
    var newContents=new Array(Contents);
    var index=0;
    var shouldend=false;
    for(var i:Transform in newContents){
       if(i==Item){
         Debug.Log(Item.name+" Has been removed from inventroy");
         newContents.RemoveAt(index);
         shouldend=true;

       }
       index++;
       if(shouldend){
         Contents=newContents.ToBuiltin(Transform);
         return;
       }
    }
}

function DebugInfo(){  
    Debug.Log("Inventory Debug - Contents");
    items=0;
    for(var i:Transform in Contents){
       items++;
       Debug.Log(i.name);
    }
    Debug.Log("Inventory contains "+items+" Item(s)");
}

Any help would be GREATLY appreciated. Thanks in advance!

more ▼

asked Mar 09 '12 at 02:12 AM

iSlaytheDe4d gravatar image

iSlaytheDe4d
1 2 2 3

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

0 answers: sort voted first
Be the first one to answer this question
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:

x4319
x2409
x152
x116
x11

asked: Mar 09 '12 at 02:12 AM

Seen: 919 times

Last Updated: Mar 09 '12 at 03:00 AM