- Home /
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!
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.
Your answer
Follow this Question
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