`UnityEngine.GameObject.AddComponent(string)' is obsolete:

How do I fix this code?


The alternative seems to be (C#)


or (JS)


as defined here: Unity - Scripting API: GameObject.AddComponent

I would recommend specifying a language in the future, particularly for small code samples like yours. Using C#, I don’t get that error (on v1.6.0b20), so I’m assuming this is JS code, but on that note, a version might be helpful as well, especially when referencing something as “obsolete” or “deprecated”.