- Home /
BCE0019: 'distanceScore' is not a member of 'float'. (JavaScript)
BCE0019: 'distanceScore' is not a member of 'float'.
I am trying to access a static variable from another script and attach that value to a float variable. Here is my code for the static variable:
static var distanceScore: float;
and the number gets assigned later in the script
here is the code for the variable i'm trying to assign:
var score: float;
score = score.distanceScore;
How can I fix this? (let me know if you think some of my other code might be the problem and I'll be sure to post it.)
I have the same problem after the upgrade to the Unity 5. Static variables are not working.
Assets/Sktypty/bolen.js(17,14): BCE0019: 'aktualnyLewel' is not a member of 'UnityEditor.$$anonymous$$enu'.
This is my bolen.js
//boen.js
#pragma strict
public var lewel:int;
function Start () {
$$anonymous$$enu.aktualnyLewel=lewel;
}
And my $$anonymous$$enu.js:
//$$anonymous$$enu.js
#pragma strict
public static var aktualnyLewel=2;
function Start(){
Debug.Log(aktualnyLewel.ToString());
}
I can not find a solution
GetComponent.().aktualnyLewel=lewel;
It also does not help nor is:
var menu : $$anonymous$$enu;
menu = GameObject.Find("$$anonymous$$enu").GetComponent($$anonymous$$enu);
menu.aktualnyLewel=lewel;
Answer by sriram90 · Mar 21, 2014 at 06:45 AM
You have to try with, Class name and access that members from another script. Basic scripting will help to fix this, here you go.
Test1.js
public static var distanceScore : float = 100.0f;
Test2.js
var score : float;
function Start ()
{
score = Test1.distanceScore;
print("Score : "+score); //Prints 100.
}
Whether you attached both the scripts to game Object ? If so, it'll work 100% And paste the code what you modified.
What I did was I added public in front of my static variable. These scripts are attached to a game object, but not the same game object. And I changed the name of the variable score to scoreFinal so that it doesn't match the name of the script "score"
You have to access class member using that Class name . like score = Test1.distanceScore; score = score.distanceScore; wont work. Try to learn basic program$$anonymous$$g.
I know, score is the name of the script. That's why I changed the variable name score to scoreFinal.
Answer by phuzik · Dec 03, 2015 at 08:18 AM
My problem solved. I had to change the name of the script. The name "Menu.js" is prohibited in Unity5.x . In Unity3.x or Unity4.x was OK. My project have GUI skin with name "Menu" and scene with name "Menu". Maybe now this it is problem.
Your answer
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
Static function and variables error 2 Answers
Resticing variables to whole numbers 3 Answers
Weird Code Error Message 2 Answers