Hello,
I am making a counter and am trying to access a value from a different script and set it equal to a int in a seperate script. Here are the two scripts? Why am I getting an error trying to get iCounter?
Thanks!
First script:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class PlayerHealth : MonoBehaviour {
public float Health = 600;
public int healthRate = 5;
public float timer = 0F;
public bool playerDead = false;
public double counter = 0;
public int iCounter;
public Text t;
public void damagePlayer (int damage){
Health -= damage;
if (Health <= 0)
{
Dead();
}
}
private void Dead(){
Destroy (this.gameObject);
playerDead = true;
Application.LoadLevel("RespawnMenu");
}
private void Update ()
{
timer += Time.deltaTime;
counter += Time.deltaTime;
iCounter = (int)counter;
t.text = "" + iCounter;
if (timer > 2) {
Health += healthRate;
timer = 0;
}
if (Health > 600) {
Health = 600;
}
}
}
Second script:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class RespawnCounter : MonoBehaviour {
public int FinalCount;
public Text t;
void Update(){
FinalCounter ();
}
public void FinalCounter(){
FinalCount = iCounter;
t.text = "" + FinalCount;
}
}