- Home /
Trouble Adjusting Stats (MP After Casting A Spell)
I have my initial stats for MP as follows, originating from the Screen Stats Canvas:
public int playermpactual; public int playermptotal;
void SetInitial() { playerhp.text = playerhpactual + "/" + playerhptotal.ToString (); playermp.text = playermpactual + "/" + playermptotal.ToString (); }
void Update () { UpdateStats (); }
public void UpdateStats()
{
playerhp.text = playerhpactual + "/" + playerhptotal.ToString ();
playermp.text = playermpactual + "/" + playermptotal.ToString ();
}
When I cast a Spell, in script SpellCast attached to the player, I have the following:
private ScreenStats screenStats; private UpdateStats updateStats; public int MPactual; public int MPtotal;
private Text MPText;
// Use this for initialization
void Start () {
SetInitial ();
}
void SetInitial()
{
updateStats = GetComponent<UpdateStats> ();
screenStats = GetComponent<ScreenStats> ();
projectileplace = transform;
MPactual = screenStats.playermpactual;
MPtotal = screenStats.playermptotal;
MPText = screenStats.playermp;
}
MPactual = screenStats.playermpactual; MPtotal = screenStats.playermptotal;
void Update () { if (Input.GetKey(KeyCode.J)) { throwprojectile (); MPCost(); } }
public void throwprojectile()
{
GameObject projectile = (GameObject) Instantiate(projectileobject, projectileplace.TransformPoint (0, 20, 10), projectileplace.rotation * Quaternion.Euler (-90f, 0f, 0f));
projectile.GetComponent<Rigidbody> ().AddForce (projectileplace.forward * force, ForceMode.Impulse);
Destroy (projectile, 3);
MPCost ();
}
public void MPCost()
{
MPactual = MPactual - 8;
Debug.Log ("MP Cost");
}
The debug shows up but no stats change in my text.
Answer by Chimer0s · Mar 10, 2020 at 04:46 AM
You're updating the value of MPActual only in your second script, not in the screenStats script. You'll need to change
public void MPCost()
{
MPactual = MPactual - 8;
Debug.Log ("MP Cost");
}
to something like
public void MPCost()
{
MPactual = MPactual - 8;
screenStats.playermpactual = MPactual;
Debug.Log ("MP Cost");
}
I made $$anonymous$$PText public and assigned the Text to it.
It DOES change the $$anonymous$$P, however only when I am holding the button down. So, i can hold it down and watch the $$anonymous$$P drop to -200 and then release the key, and the $$anonymous$$P goes back to its default 15/15 for some reason.
Answer by TheRedGuy90 · Mar 12, 2020 at 02:18 AM
I still have no change. I'm going to keep working with this. Thank you for responding.
Your answer
Follow this Question
Related Questions
A question about making spells(magic) 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How can I move a player toward a gameobject by clickling an image 0 Answers