Hello,
I think this problem is between “pure javascript” and Unity implementation.
Well, I want to create a variable in javascript called “speed”, and I want to expose it in Unity property editor.
So I wrote, in my javascript code:
var speed:int;
The problem I do not want to assign a value (e.g. 100 km/h), but a name: “LOW”, “MEDIUM”, “HI”.
So I want to see those options in the property editor
Is it possible? How?
Thank you for your help (I’m still a beginner in Unity)!
If one wants to access to “enum” defined in a script, that enum is like a “public static” variable. It means you can simply recall it without specifying the script name.
I made a script called TInfoWaypoint.js, and I inserted:
enum enumSuggestedSpeed {Low, Medium, High}
I applied this script to an object in the scene (a GameObject I use as a waypoint).
Now I have another object (a ship), and I use the following code in a script attached to this ship:
function getSpeedBasedOnWaypoint() {
// Valore di ritorno
var ret:float;
// Divido la pMaxSpeed/3, ed ottengo "Low".
var tmpSpeedUnit:float = pMaxSpeed / 3.0;
if(nextWaypoint.wpSuggestedSpeed == enumSuggestedSpeed.Low) {
ret = tmpSpeedUnit;
} else if(nextWaypoint.wpSuggestedSpeed == enumSuggestedSpeed.Medium) {
ret = tmpSpeedUnit * 2;
} else if(nextWaypoint.wpSuggestedSpeed == enumSuggestedSpeed.High) {
ret = pMaxSpeed;
}
return ret;
}
As you can see, I used enumSuggestedSpeed.Low
without any explicit reference to TInfoWaypoint.js or its instance.
The object are even different.
I can successfully compile and use that function.
I did not try to put enum in a code not instanced (not attached to a GameObject).
using UnityEngine;
public class FBX_Sync : MonoBehaviour {
[System.Serializable]
public class ColliderSync
{
public Type type;
public enum Type
{
BoxCollider,
SphereCollider,
CapsuleCollider
}
}
}
In another script, I am forced to refer to the ColliderSync enumeration like this: