Could someone teach me on how to access another script javascript in the same game object ? Im a complete newbie in C# and I couldnt understand what the documentation in Unity for accessing component works for C#…
This is what I would like to achieve in C#
(Using Javascript)
function Update()
{
if(gameObject.GetComponent("keyboardInputCheck").disableWASD)
{
//do something
}
}
It’s not completely clear to me what you’re asking, but is this:
void Update()
{
if (GetComponent<keyboardInputCheck>().disableWASD)
{
//do something
}
}
What you’re looking for? (Note that you can drop the ‘gameObject’ reference in C#, and presumably in UnityScript as well.)
I believe there’s an overload of GetComponent() that takes a string, so I’d expect the corresponding statement in your original code would work as is also.