Saturday, December 7, 2019

c# - Unity Events with Arguments


I'm fairly new to Unity and I can't really get my head around the best way to communicate between scripts. For example, if the character jumps, what is the best way to inform other scripts (such as ground objects) to act on the characters velocity and move.


I recently had a look at this which describes how to make a messaging system. My problem with this, is that I'm not sure how to pass arguments when triggering events.


For example, If I wanted to do:


if (Input.GetButtonDown("Fire1")){

EventManager.TriggerEvent("Jump", jumpVelocity);
}

...

EventManager.StartListening("Jump", OnJump);

void OnJump(velocity)
{
//scroll ground objects horizontally

}

How could I add arguments to a messaging system, or would there be a better way?




No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...