Am currently working in UI for a game app. I do have created a Score Calculator script which handles score points. I do have another script, player Movement… which handles player’s health.
I want Score Calculator script to seek health variable from Player movement script.
Score Calculator Script:
{
// Use this for initialization
public TextMesh myText ;
void Start () {
score=0 ; //reset back Score to zero
myText = GetComponent<TextMesh>();
InvokeRepeating("Updates",0,0.05f);
}
// Update is called once per frame
public static float score ;
public float incrementSpeed ;
void Updates () {
if(player.health < 0) return ;
score+=incrementSpeed*Time.deltaTime*player.health ;
myText.text = ""+Mathf.Round(score);
if( player.health==0 )
{
transform.Translate(Time.deltaTime*40,0,0);
}
}
void OnBecameInvisible()
{
Destroy(gameObject);
}
}
Player Movement Script
{
// Health Variable
public int health;
void Start()
{
health = 100;
myTransform = transform;
}
void OnGUI()
{
GUI.Label(new Rect(10, 10, 100, 20), health.ToString());
}
public void DecreaseHealth(int n)
{
health-=n;
if(health<=0)Destroy(gameObject);
}
}