- Home /
When i call some variables to an other second script i have a problem
Hello everyone. My problem is as follows :
I have 3 Diferent Java scripts
First Sript name i just call is "PlayerHp", Second Script Name is "PlayerSkill", Third script Name PlayerStats
PlayerHp:
static var curHp = 80;
static var dieHp = 0;
static var maxHp = 100;
PlayerSkill:
var damageHp = 10;
private var curHp = PlayerHp.curHp;
private var dieHp = PlayerHp.dieHp;
private var maxHp = PlayerHp.maxHp;
function Update() {
if(Input.GetButton("Attack") && curHp > dieHp) {
curHp = curHp - damageHp;
Debug.Log ("Hp" + curHp);
}
PlayerStats:
public var curHp = PlayerHp.curHp;
public var dieHp = PlayerHp.dieHp;
public var maxHp = PlayerHp.maxHp;
but when made some change by PlayerSkill (for example pressing Input.GetButton("Attack"), then the stats made change the didn't update to playerHp or PlayerStats. How can i fix that?
Answer by cjdev · Apr 19, 2013 at 05:53 PM
Instead of assigning new private variables for your player stats use the static variables in your PlayerSkill Update function instead.
function Update() {
if(Input.GetButton("Attack") && PlayerHp.curHp > PlayerHp.dieHp) {
PlayerHp.curHp = PlayerHp.curHp - PlayerHp.damageHp;
Debug.Log ("Hp" + PlayerHp.curHp);
}
}
Your answer
Follow this Question
Related Questions
UCE0001: ';' expected. Inser a semicolon at the end 1 Answer
Problems with creating custom EditorGUI for script 0 Answers
Weird error every frame 1 Answer
Scripting error! 1 Answer