- Home /
Scripting help (sending messages?)
ok so i want to make an inventory for my game.
i want it to open when i press the mouse on the inventory picture so i added the script
function onMouseDown ()
i need the function to open the other picture of the bag grid
how would i be able to make this happen.
and if some one could tell me how to set up a grid that i can place clickable abjects too and how to make the clicked button to send a message to a receiver ex.
press robe - robe icon goes into the armor window - and gives the empty the message to add new object robe and destroy other object that was on there before (replace them)- and that send a message to stats saying to add more mana+ health +armor+spell power.
thank you
Answer by qJake · Jun 25, 2010 at 06:44 PM
Try not to ask more than one question in a single post, and try not to ask such a broad question in the future. Regardless, I'll do my best to point you in the right direction.
First, you can create a grid of buttons using this function:
http://unity3d.com/support/documentation/ScriptReference/GUI.SelectionGrid.html
You can make it appear and disappear using a script like this (but not exactly this, don't copy and paste it):
bool inventoryVisible = false;
void OnMouseDown() { inventoryVisible = !inventoryVisible; }
void OnGUI() { if(inventoryVisible) { // GUI Selection Grid Code Here } }
I can't help you with sending messages to other scripts, simply because you have provided little to no detail about your specific setup, and since there are many different ways of calling functions of other objects, I can't be specific. I can, however, link you to this page, which describes in detail how to access other scripts on other game objects:
http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Objects.html
could you make one that i can copy and paste? Im really bad at scripting and i ordered a text book for java scripting but it wont come till 2 weeks
Nope, I won't. This isn't even real code, it's just kind of an "overview" of how you could do it. You need to code this yourself, we won't code for you here.
You cant just copy and paste something as advanced as an inventory system. You need to code it yourself to make it work with YOUR game setup, that most likely is too hard to explain to others and your gonna wanna link to other scripts and gameObjects. You will want to maintain it and update it yourself too.
Btw you need a Unity based text book because JavaScript is much different from UnityScript (thats what unity's version of JavaScript is called). Now your JavaScript book will help with some stuff like declaring functions and that. If you want to learn JavaScript (NOT UnityScript) go here: www.codeacademy.com/ <- they have helpful JavaScript tutorials which will help with basic unity things like variables, function, and for loops.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Setting Scroll View Width GUILayout 1 Answer
Hotbar and item pickups? 1 Answer
Script Not Working 0 Answers
Adding Item object to Inventory List 0 Answers