- Home /
Question by
andrewnobody · Jun 24, 2013 at 12:31 PM ·
javascripterrorfunctionclassoutside
Access function (and variable) outside class in the class in Javascript.
So I have this code:
function SomeFunction() {
Debug.Log("Log");
}
class TestClass {
var SomeVar : int = 0;
function Foo() {
SomeFunction();
}
}
And I end up with this error:
BCE0005: Unknown identifier: 'SomeFunction'.
I can't figure out what's wrong.
Edit: Also I can't access variables that are outside class. I need to get something from Unity like prefab etc.
Comment
Best Answer
Answer by Loius · Jun 24, 2013 at 05:11 PM
You can't access variables or functions outside a class. If you need something accessible from anywhere, you want a "static" utility class:
public static class Whatever() {
public static function SomeFunction() {
}
}
class Thing() {
function One() { Whatever.SomeFunction(); }
}
Your answer
Follow this Question
Related Questions
Error: expecting ( 1 Answer
running code outside of update! 3 Answers
Incremental game need help 1 Answer
Similar scripts but error on one and not the other 1 Answer
Script is causing immense lag, and I don't know what's causing it. 2 Answers