I have three objects in play: Player1, Player2, and Duel_Arena. I need to make Duel_Arena calculate a fight between Player1 and Player2, taking into account their health, weapon and armor variables. Player1 and Player2 both use the same PlayerHealth, Armor and Weapon scripts. The Duel script is able to access the variables on the objects, but the Duel script won’t do the math. Here’s the code:
public class Duel : MonoBehaviour {
public bool BeginDuel;
//player 1 stats
public PlayerHealth P1Health;
public Armor P1armor;
public Weapon P1weapon;
public Potion P1potion;
//player 2 stats
public PlayerHealth P2Health;
public Armor P2armor;
public Weapon P2weapon;
public Potion P2potion;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (BeginDuel==true)
{
//player 1 attacks first
//P1Health = Player1attack (P1Health, P2weapon, P1armor);
// var otherScript: OtherScript = GetComponent(OtherScript);
//otherScript.DoSomething();
//P2Health = P2Health - (P1weapon - P2armor);
//player 2 attacks second
//P1Health = P1Health - (P2weapon - P2armor);
}
else
{
}
}
public int Player1attack(int x, int y, int z)
{
int result;
result = x - (y - z);
return result;
}
}