Following BergZerg Arcade Inventory Tutorial 1-2
Within the tutorial he typed this so one script can execute a function in another script. However CSharpMessenger Extended is required to use some of the functions.
I disagree with this and i know there is another way for scripts to execute another scripts function without CSharpMessenger Extended. How do i do this, i have looked but problems occur…
Press “Inventory” button (Q) to send out a message.
if (Input.GetButton ("Inventory"))
{
SendMessage("ToggleInventoryWindow");
}
Listener hears the message and executes the function on the script
private void OnEnable(){
Messenger.AddListener ("ToggleInventory", ToggleInventoryWindow);
}
private void OnDisable(){
Messenger.RemoveListener ("ToggleInventory", ToggleInventoryWindow);
}
The final result
public void ToggleInventoryWindow() {
if (Input.GetButton ("Inventory"))
{
DisplayInventory = !DisplayInventory;
}