Is it possible to access a variable from another function in the same script? I need to access a variable from my update function because if I declare it outside it won’t work. Is this possible?
In my opinion it’s impossible to access method variable outside this method.
Correct me if i’m wrong but i see something like this:
function someFunction()
{
//You want this variable to be edited in otherFunction();
var x = value;
}
// and here you want to access variable x
function otherFunction()
{
x = otherValue;
}
If thats what you want then i think its not possible and you should do loke this:
//That's your variable that you can access within any method
var x : int = value;
function someFunction()
{
x = otherValue;
}
function otherFunction()
{
x = anotherValue;
}
Yes I think it would look like this as shown on script reference
`// Calls the function ApplyDamage with a value of 5
SendMessage ("ApplyDamage", 5.0);
// Every script attached to the game object
// that has a ApplyDamage function will be called.
function ApplyDamage (damage : float) {
print (damage);
}`