Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by iSlaytheDe4d · Mar 09, 2012 at 02:12 AM · cameraraycastcrosshairselectpickups

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Raycast based on crosshair on screen 1 Answer

Raycast hitting objects to the left of my player 1 Answer

Ray Cast not working for camera. 1 Answer

Raycast in camera 1 Answer

How to rotate a camera like Google Earth? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges