- Home /
GetComponent on iOS?
Hi. When I am trying to affect the public variable "ABC" in the script "TEST". This piece of code works perfectly when the current platform in Unity is set to Windows/Mac. But when I try to develop for iOS, I get the error " ABC' is not a member of 'UnityEngine.Component". What is wrong? Thanks
MyObject.GetComponent("TEST").ABC=1;
Answer by Eric5h5 · Apr 01, 2012 at 11:49 PM
Never use quotes in GetComponent; that makes it return Component instead of the type, plus it's slower.
I really think that the string-based version of this method should be deprecated. In which case(s) do we need it?
@$$anonymous$$ryptos: (Bit of a delayed response here....) Well, actually I did use it recently, in a situation where the component might or might not exist in the project, so if I didn't use quotes then it wouldn't compile in those cases where the component doesn't exist. That's not exactly a typical situation though. So by "never" I mean "almost never". ;)
Your answer
Follow this Question
Related Questions
scripting question 1 Answer
Enable or Disable Autorotation Animation option 2 Answers
2D Sidescroller: Change camera position? 1 Answer
I want to have FPS iOS tutorials. 0 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers