- Home /
Find Object with variable, not a name.
Hi guys, this might be confusing so i'll just write up an example.
Ability1 = Player.Getcomponent("Monster")
How would i replace ("Monster") with (Monster)
So, instead of defining a single script, i can make it a variable which can be changed whenever. e.g., var Monster = "Monster1";
Thanks
What type do you wish the $$anonymous$$onster var to be ?
Ask questions by adding comments to the question. Do NOT ask questions in the answers section!
Just a string/text.
Im trying to create my own battle system, which handles the enemies and player, and thus, depending on the different enemy or player ally, i would like to change one variable, which would radically change what is displayed in the battle system.
Answer by BimSekai · Jul 12, 2013 at 03:33 PM
string myType = "Monster";
Ability1 = Player.GetComponent(myType);
myType = "Somethingelsethanmonster";
Ability1 = Player.GetComponent(myType);
Does this work for you ?
Ah it does work!
It was my own fault i think, i was trying to define and reference the variable, but i needed to define the variable after the 'Start' function.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Referencing variables / functions on another script 1 Answer
Creating & accessing a function from a diffrent "OnTriggerEnter" Function 1 Answer
why do I need to type variables classes? 2 Answers
Accessing Variables within another gameobject's script 2 Answers