Currently i made a small script to test functionality in another script called Health …this script resides within an EmptyGameobject named Health as well …if that makes sense…(Player/Health/Health)…Now the big problem is that this script is a players health in a multiplayer game …so its going to be instantiated allot with the same name,so i cant use the transform.find
function because it wouldn’t know which to access…how can I reference the specific script called Health within the parent?
Code:
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
void OnGUI() {
Transform HealthTransform;
HealthTransform = transform.FindChild("Health");
Health health = HealthTransform.GetComponent<Health>();
if (GUI.Button(new Rect(Screen.width / 1.5f,Screen.height/4,100,25),"Regain Health")) {
health.modifyHealth(10);
}
if (GUI.Button(new Rect(Screen.width / 1.5f,Screen.height/4 + Screen.height/10,100,25),"Take Damage")) {
health.modifyHealth(-3);
}
if (GUI.Button(new Rect(Screen.width / 1.5f,Screen.height/4 + Screen.height/10 * 2,100,25),"Add Heart")) {
health.AddHearts(1);
}
}
}