adamistheman
adamistheman
CC#
Created by adamistheman on 2/9/2023 in #help
❔ Understanding Delegates
Hi there. I'm a bit new to delegates. There are a couple things that I would like to straighten out. For one, I don't exactly know what they are, but do I know how they can be used. I know how to create one, but I do not know their limitations nor how to subscribe with the question mark (?). Also, I have another thought about the use case of a Delegate, but I'm not sure if the way I'm thinking about it can be used this way.
/*This is an example of "can I use a Delegate this way as well"*/

private int Health, MagicPoints, ExperiencePoints;

private delegate int StatBars(int Hp, int Mp, int Xp);

private void Start()
{
PassExample(Health);
}
private void PassExample(StatBars myStats)
{
myStats(Health, MagicPoints, ExperiencePoints);
}

private void Health(int hp, int mp, int xp)
{
hp = Health = 25;
mp = MagicPoints = 50;
xp = ExperiencePoints = 0;
}
/*This is an example of "can I use a Delegate this way as well"*/

private int Health, MagicPoints, ExperiencePoints;

private delegate int StatBars(int Hp, int Mp, int Xp);

private void Start()
{
PassExample(Health);
}
private void PassExample(StatBars myStats)
{
myStats(Health, MagicPoints, ExperiencePoints);
}

private void Health(int hp, int mp, int xp)
{
hp = Health = 25;
mp = MagicPoints = 50;
xp = ExperiencePoints = 0;
}
When writing it out, it looks a tad improper but I am unaware of if this is acceptable.
15 replies
CC#
Created by adamistheman on 1/28/2023 in #help
❔ Unity: NewInputSystem: MultiTap
5 replies
CC#
Created by adamistheman on 1/26/2023 in #help
Something Ain't right... -_-
16 replies
CC#
Created by adamistheman on 12/27/2022 in #help
❔ I'm not sure what to use here... A Multidimensional Array? A hash table? A Matrix?
5 replies