- Home /
Error(non static member): using public variable from other script JS
i have this code from a script I created for collision
function onTriggerEnter(col : Collision)
{
if(col.gameObject.name == "Current Power Up")
{
Destroy(col.gameObject);
powerUp.countDown = powerUp.powerUpTime;
}
}
and needs to access this variables and change the values
public var powerUpTime : float = 10.0;
public var powerUpEffectTime : float = 5.0;
I get this error.....how can i solve it?
Assets/snakeCollision.js(16,17): BCE0020: An instance of type 'powerUp' is required to access non static member 'countDown'.
Assets/snakeCollision.js(16,37): BCE0020: An instance of type 'powerUp' is required to access non static member 'powerUpTime'.
this will also be helpfull in future when i get to make the power up effecting the character.
Thanks in advance Joseph
after a bit research i found that i made some errors my self.. Collision should be Collider and OnTriggerEnter is written wrong, anyway... i managed to get it to work
function OnTriggerEnter(col : Collider)
{
if(col.gameObject.name == "Current Power Up")
{
Debug.Log("Trigger Successfull");
Destroy(col.gameObject);
powerUpScript.countDown = powerUpScript.powerUpTime;
}
}
Answer by Joseph118 · Feb 22, 2013 at 02:49 PM
after a bit research i found that i made some errors my self.. Collision should be Collider and OnTriggerEnter is written wrong, anyway... i managed to get it to work
function OnTriggerEnter(col : Collider) {
if(col.gameObject.name == "Current Power Up")
{
Debug.Log("Trigger Successfull");
Destroy(col.gameObject);
powerUpScript.countDown = powerUpScript.powerUpTime;
}
}