Reputation: 111
I'm doing a game in Unity and suddenly this problem appeared. Is it possible to get the parameter of a method in C#?
for example:
void Print1(string message)
{
print("message");
}
void Print2(string message)
{
//PseudoCode
message = Print1message;
print("message")
}
So, let's say that the method Print1 has been called and then, we want that the method Print2 get that same value. For example:
Print1 receives the parameter "Hello World" and if we call Print2, we should get the parameter "Hello World" of Print1 and show it. Is this possible?
Upvotes: 0
Views: 122
Reputation: 988
You should use global variable like this :
string GlobalMessage;
void Print1(string message)
{
GlobalMessage=message;
print("message");
}
void Print2(string message)
{
message = GlobalMessage;
print("message")
}`enter code here`
Upvotes: 1
Reputation: 10393
This?
string Print1(string message)
{
print(message);
return message;
}
void Print2(string message)
{
var msg = Print1(message);
print(msg);
}
Upvotes: 0