Hi, it's working when I use this script using javascript but not in c# //javascript var someScript : ExampleScript = GetComponent (ExampleScript); someScript.DoSomething (); //c# ExampleScript someScript; someScript = GetComponent (ExampleScript); //error here. someScript.DoSomething ();
Or Code (csharp): Type variableName = (Type) objectName.GetComponent(typeof(Type)); Which has the advantage, that it doesn't immediatly create a NullReferenceException during runtime, when the component does not exist and therefore GetComponent returns null. You could then do a check Code (csharp): if (variableName != null) { ... } to avoid trouble when accessing variableName... another option, of course, is using GetComponent(...) as Type embedded in some try { ... } catch (NullReferenceException exc) { ... }...