Quantcast
Channel: Answers for "How can I reference a variable whose name is determined by a string? (C#)"
Browsing all 6 articles
Browse latest View live

Answer by LoneMonkey

Not exactly for sure how this would be done without putting my thinking hat on but as a quick alternative you could call a function on the Lights script from the Switch script passing the correct...

View Article


Answer by Guidanel

It's not really an answer to your question but with your example shouldn't you give references of your 3 lights to your Switch script? This way it can set the lights on and off immediately depending on...

View Article


Answer by NewPath

What you are looking for is achieved through reflection. The caveat is this only works with public properties or members. public bool RedLight { get; set; } private void SetLight(string name, bool...

View Article

Answer by LoneMonkey

Not exactly for sure how this would be done without putting my thinking hat on but as a quick alternative you could call a function on the Lights script from the Switch script passing the correct...

View Article

Answer by GiyomuGames

It's not really an answer to your question but with your example shouldn't you give references of your 3 lights to your Switch script? This way it can set the lights on and off immediately depending on...

View Article


Answer by NewPath

What you are looking for is achieved through reflection. The caveat is this only works with public properties or members. public bool RedLight { get; set; } private void SetLight(string name, bool...

View Article
Browsing all 6 articles
Browse latest View live