- Home /
Get game component type?
I have the following code in C#:
GameObject[] obj = GameObject.FindGameObjectsWithTag("Player");
foreach(GameObject o in obj)
{
o.transform.position = new Vector3(o.transform.position.x, o.transform.position.y + 5,
o.transform.position.z);
Health h = o.GetComponent<Health>();
}
It all works fine save for the line Health h = o.GetComponent(); and the reason for this is the type Health is undefined.
Health is a js script which can be accessed by js functions simply as 'Health', but as far as I can see there is no way to find it in C#.
Is this just a limitation of Unity's scripting system (which would be understandable) or can this be done and I'm just going about it the wrong way?
Answer by asafsitner · Sep 24, 2011 at 04:22 PM
That happens because of compile order. If you want your c# and JS scripts to talk nicely to each other you'll have to put the JS scripts under Assets/Plugins folder (possibly also Resources folder, but I haven't confirmed that yet).
Using both languages seems like more trouble than it's worth it. I'd advise to stick to one of them whenever possible.
Your answer
Follow this Question
Related Questions
when mouse is on a object do this 2 Answers
press e to speek -1 Answers
Making changes to a terrian in game 1 Answer
Calling C# Classes from JS 1 Answer
Destroy object with more clicks depending on Scale? 0 Answers