Hi! I want to make a GUI that shows my bullet damage, however, the variable (I’m using a float) of the damage is in a diferent script. I want to access my Damage float from another script.
My Scripts:
public class BulletScript : MonoBehaviour {
public float Damage = 50;
void OnCollisionEnter(Collision Other){
if ( Other.gameObject.GetComponent( typeof(AIscript) ) != null && Other.gameObject != objPlayer ) // if we have hit a character and it is not the player
{
AIscript ptrScriptAI = (AIscript) Other.gameObject.GetComponent( typeof(AIscript) );
ptrScriptAI.health -= Damage;
Instantiate(ptrScriptVariable.parAlienHit, transform.position, Quaternion.identity );
removeMe();
}
I want to take the float Damage in put it in to my GUI. My other script:
public class AIscript : MonoBehaviour {
public GUISkin Heatlh;
public GUISkin damage;
public float health = 50f;
void OnGUI()
{
if (thisIsPlayer == true)
{
GUI.skin = Heatlh;
GUI.Label (new Rect (Screen.width * (100.4f/120.55f),Screen.height * (100.1f/120.3f),Screen.width * (5f/12.55f), Screen.height * (5f/12.3f)),"Health: " + health.ToString()+ "%");
}
}