- Home /
Getting Variable value from another object?
Anyone know how to fix this issue? (Java) Here's the part I'm stuck at. I'm trying to find a variable name from a different object (Object is the player, script on it is called "PlayerAnimationController") I'm looking for the variable called "Facing" in said script. Then check if the Facing Variable is 0 (Left) or 1 (Right). But I'm having trouble accessing it. My error is:
Assets/SamuraiScroller/Scripts/EnergyBar.js(83,70): BCE0020: An instance of type 'PlayerAnimationController' is required to access non static member 'Facing'. _
Code snipet of the problematic area:
if (Active == 2){
var Facingscript : PlayerAnimationController;
Facingscript = GetComponent("PlayerAnimationController");
audio.clip = ReleaseSound;
audio.Play();
var Spawnpoint = GameObject.Find("Special_Attack_Spawn");
var ChargeAttack = Instantiate(SpecialAttack, Spawnpoint.transform.position, transform.rotation);
if(PlayerAnimationController.Facing == 0)
{
ChargeAttack.rigidbody.AddForce(Vector3.Left * AttackSpeed);
}
if(PlayerAnimationController.Facing == 1)
{
ChargeAttack.rigidbody.AddForce(Vector3.Right * AttackSpeed);
}
Active = 1;
yield WaitForSeconds (audio.clip.length);
Active = 0;
}
}
This is THE $$anonymous$$OST AS$$anonymous$$ED QUESTION EVER! I see it at least twice a day. Anyone wanna explain 'the reference manual' and using 'search' here? I'm tired.
This kind of question should not pass moderation.
To moderators (such as myself): there is a "send message" option along "publish". It can be used to notify the user, so please use it.
I've searched for it for hours and no one really explains it they just send you to the reference manual
Answer by Seth-Bergman · Aug 16, 2012 at 01:42 AM
Ok, here's the deal:
Facingscript = GetComponent("PlayerAnimationController");
first off, this will return type of "Object" rather than "PlayerAnimationController" like you want
Facingscript = GetComponent(PlayerAnimationController);
this would work if you were looking for a component on the SAME object
var player : GameObject = GameObject.Find("NameOfPlayerObject");
var Facingscript : PlayerAnimationController = player.GetComponent(PlayerAnimationController);
this is more like what you need
Your answer
Follow this Question
Related Questions
Accessing a variable within a function.... GetComponent() 2 Answers
Variable from a external script not being effected 2 Answers
Running faster while flashlight is off 3 Answers
GetComponent with variable script possible? 1 Answer
Boolean not switching? 2 Answers