I’ve spent all night in the same place I’m confused and not sure if I’m even close to what I’m trying to accomplish at this point. I would just like to load my pattack int from my Player script into my Button1 script. Then do button1hp - pattack in the button1 script.
[CS0120]
Assets/Scripts/Button1.cs(29,26): error CS0120: An object reference is required to access non-static member `Player.pattack’
[CS0019]
Assets/Scripts/Button1.cs(37,9): error CS0019: Operator -=' cannot be applied to operands of type
int’ and `Player
Button1.cs
using UnityEngine;
using System.Collections;
public class Button1 : MonoBehaviour {
Player pattack;
void Start() {
pattack = gameObject.AddComponent<Player>();
}
public UnityEngine.UI.Text Button1Display;
public int button1hp = 10;
void Update() {
pattack = Player.pattack;
Button1Display.text = "HP: " + button1hp;
}
public void OnMouseDown() {
button1hp -= pattack;
}
}
Player.cs
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
public UnityEngine.UI.Text PBaseLevelDisplay;
public UnityEngine.UI.Text PJobLevelDisplay;
public UnityEngine.UI.Text PBaseExpDisplay;
public UnityEngine.UI.Text PJobExpDisplay;
public UnityEngine.UI.Text PHealthDisplay;
public UnityEngine.UI.Text PAttackDisplay;
public UnityEngine.UI.Text PDefenseDisplay;
public UnityEngine.UI.Text PTClicksDisplay;
public int pbaselevel = 1;
public int pjoblevel = 1;
public int pbaseexp = 0;
public int pjobexp = 0;
public int phealth = 10;
public int pattack = 2;
public int pdefense = 1;
public int ptclicks = 0;
void Update()
{
PBaseLevelDisplay.text = "Base Level: " + pbaselevel;
PJobLevelDisplay.text = "Job Level: " + pjoblevel;
PBaseExpDisplay.text = "Base Exp: " + pbaseexp;
PJobExpDisplay.text = "Job Exp: " + pjobexp;
PHealthDisplay.text = "Health: " + phealth;
PAttackDisplay.text = "Attack: " + pattack;
PDefenseDisplay.text = "Defense: " + pdefense;
PTClicksDisplay.text = "Total Clicks: " + ptclicks;
}
void Awake(){
Instance = this;
}
}