|
|
#1 | ||||||||
|
Junior Member
|
Hello,
I am designing a GUI system for my Unity3D project in C# and I want to handle button presses in the best way that I can. Here's how I would do it in C++ ... Code:
void StartNewGame()
{
//SomeCode
}
void Main()
{
ButtonClass NewGame;
NewGame.FunctionPointerIfPressed = StartNewGame;
}
Bottom Line: I have a container of a button class and I want each button to be able reference a function so I can call said function when button is pressed. |
||||||||
|
|
|
|
|
#2 | ||||||||
|
Administrator
Location: UK |
Should be pretty simple. In Unity, a Button should have a 'Clicked Event' function callback already in place for you to fill in.
__________________
Steven Yau [Alix Games Blog] [Portfolio] [How I broke into the Games Industry] [Why I left my Games Job] [How to be a Games Tester] [Getting back into the Game] |
||||||||
|
|
|
|
|
#3 | ||||||||
|
Moderator
Location: Netherlands |
Maybe I'm oversimplifying here, but perhaps you mean something like this?
Code:
NewGame.Click += StartNewGame;
__________________
I'm a web developer by profession, but a game developer by heart. Uh oh! The princess is in another signature! |
||||||||
|
|
|
|
|
#4 | |||||||||
|
Junior Member
|
Quote:
Code:
if(GUI.Button(rectangle, "message"))
{
//code here if pressed
}
ProtectorOne, That's how buttons work in C# Forms Programming but I'm not sure how to set up an event system that supports that in Unity =/. Unity does support .NET 4.0. Thank you for the replies. |
|||||||||
|
|
|
|
|
#5 | ||||||||
|
Senior Member
Location: Apex NC, USA |
John, I'm not familiar with Unity, but I think what you're looking for are C# events and delegates. I haven't found a great article on them, but this one tries to explain:
http://www.codeproject.com/KB/cs/csevents01.aspx Basically, you want to create your own custom events and event handlers (delegates/callbacks). If you need more info search on "C# delegates" or "C# event handling". Hope that helps. |
||||||||
|
|
|
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
Powered by vBulletin® Version 3.6.9
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
All times are GMT -8. The time now is 09:44 PM.




























Linear Mode

