Question by
zak666 · Jul 06, 2016 at 05:35 AM ·
script.getcomponentscriptingbasics
attleshipAI.cs(65,90): error CS0176: Static member `battleshipSide.Underattack' cannot be accessed with an instance reference, qualify it with a type name instead
I don't understand why i can't accesses the script on the game object, using get component of the game object i want to change a bool to true on that game object sop my other ships cannot target the same ship.
some reason I'm getting this: BattleshipAI.cs(65,90): error CS0176: Static member `battleshipSide.Underattack' cannot be accessed with an instance reference, qualify it with a type name instead
for line: Target.GetComponent().Underattack = true;
Target = null;
if (GameObject.FindWithTag("EnemyBroadside") != null)
{
Target = GameObject.FindWithTag("EnemyBroadside");
}
if (Target != null) {
//setattacking
dist = Vector3.Distance (Target.transform.position, this.transform.position);
if (dist < 500 && Target.GetComponent<battleshipSide>().Underattack != true) {
Attacking = true;
Patrolling = false;
Defending = false;
DefenceOwned = false;
Target.GetComponent<battleshipSide>().Underattack = true; //this target can no longer be tergeted by other battleships.
}
} else {
Target = null;
} Target = null;
if (GameObject.FindWithTag("EnemyBroadside") != null)
{
Target = GameObject.FindWithTag("EnemyBroadside");
}
if (Target != null) {
//setattacking
dist = Vector3.Distance (Target.transform.position, this.transform.position);
if (dist < 500 && Target.GetComponent<battleshipSide>().Underattack != true) {
Attacking = true;
Patrolling = false;
Defending = false;
DefenceOwned = false;
Target.GetComponent<battleshipSide>().Underattack = true; //this target can no longer be tergeted by other battleships.
}
} else {
Target = null;
}
Comment
Best Answer
Answer by HarshadK · Jul 06, 2016 at 06:00 AM
As your Underattack
variable from your battleshipSide
is static you can not access it with a reference as you are currently doing. You need to remove static
from your Underattack
variable and it will be resolved.