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 MithosAnnar · Mar 12, 2012 at 09:27 AM · javascriptpositionguitexture

How Do I Drag And drop GUITextures From Set Positions?

I simply want to be able to loot an enemy and have the looted item go to a default position in the inventory.

If the default position is taken, then I want the item to go to the position next to the default one.

And so on.

So far, I have an inventory system. In this script I have assigned a spot for each item:

var items : List.; var spaces : List.;

var itemCount : int;

function Awake () {

spaces.Add(Rect(279, 225, 66, 63)); spaces.Add(Rect(344, 225, 66, 63)); spaces.Add(Rect(409, 225, 66, 63));

spaces.Add(Rect(279, 160, 66, 63)); spaces.Add(Rect(344, 160, 66, 63)); spaces.Add(Rect(409, 160, 66, 63));

spaces.Add(Rect(279, 96, 66, 63)); spaces.Add(Rect(344, 96, 66, 63)); spaces.Add(Rect(409, 96, 66, 63));

spaces.Add(Rect(279, 32, 66, 63)); spaces.Add(Rect(344, 32, 66, 63)); spaces.Add(Rect(409, 32, 66, 63));

}

function Update () {

itemCount = items.Count;

for (var item in items) {

(item as GameObject).transform.position = Vector3(0, 0, 1);

for (var i = 0; i < itemCount; i++) {

item = items[i];

(item as GameObject).guiTexture.pixelInset = spaces[i];

}

}

}

But because I have set the position of the item I can't move it to another spot, any Ideas on how to correct this?

Or:

Anyone know how to drag and drop an item to another location?

Thank you for your time!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by senad · Mar 12, 2012 at 10:43 AM

Instead of using a fixed mapping for your items, you could use a map object (Dictionary in C#) to assign slots to items. This way you could say that you want item 0 to be in slot 3 and so on.

For dragging and dropping I would use the mouse down and up events to see where to move the icon to. I am sorry, I do not have any examples or tutorials, but if you search for it, you might find an example implementation.

Comment
Add comment · Show 2 · Share
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
avatar image MithosAnnar · Mar 14, 2012 at 12:05 PM 0
Share

This helped me a bit (got me searching). Thank you.

avatar image sdgd · Jan 24, 2013 at 03:10 AM 0
Share

dang and I thought I'll find solution in here

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Android: How do you position GUITexture and GUIText according to different screen sizes (JS)? 2 Answers

Position of a GameObject 2 Answers

Getting an Objects position once 2 Answers

Change object position on trigger enter 3 Answers

How to tell if two blocks are right next to each other?(2D) 1 Answer


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