I am much more familiar with C# than Java, so a lot of things are easier for me to use C#. However, some things I find easier in Unity in Java.
Can I create a C# script that exposes variables, and access those variables from the java script?
What I have is a C# script called PlayerControl which has a variable exposed called Health.
I have a 2nd script called GUIControl. This script is in Java.
Both scripts are attached to the Player object.
I want the GUI control to display a label on the screen containing the Health from the PlayerControl script.
I have tried everything I can think of. Here are a couple of the things I have tried...
var PlayerScript:PlayerControl;
function Start() { PlayerScript = GetComponent(PlayerControl); }
function OnGUI () { DisplayHealth(); }
function DisplayHealth() { GUI.Label(Rect(0,0,100,50), PlayerScript.Health); }
This results in the following error...
Assets/My Scripts/GUIControl.js(1,18): BCE0018: The name 'PlayerControl' does not denote a valid type.
I have also tried eliminating the Start function, and changing the variable declaration to...
var PlayerScript:PlayerControl = GetComponent(PlayerControl);
This results in the same error.
I have also tried eliminating the Type from the declaration like this...
var PlayerScript = GetComponent(PlayerControl);
This results in the following error...
Assets/My Scripts/GUIControl.js(1,33): BCE0005: Unknown identifier: 'PlayerControl'.
I have read everything I can find in the manual, and also read several of the other posts concerning accessing variables in one script from another and cannot seem to make this work.
I am sure I am doing something obviously wrong, I just cant seem to figure out what it is.
Any help anyone can give me would be greatly appreciated.