- Home /
health 'not a member of component' Android Only
.health not a member of component error (all other get component works on this script). Works on windows...
Could somebody please tell me what is wrong.
#pragma strict
var i = 0;
var ii = 0;
var mode = 0;
var stuff : Component;
var player : GameObject;
var solder : float = 0;
var steel : float = 0;
var gold : float = 0;
var plastic : float = 0;
var hardplastic : float = 0;
var solidplastic : float = 0;
var total = 0;
function Start () {
total = Random.Range(0,6000);
player = GameObject.Find("armour");
stuff = GameObject.Find("armour").GetComponent("GameStats");
}
function Update() {
i++;
ii++;
if (i >= 50) {
i = 0;
gameObject.transform.LookAt(player.transform);
if (Vector3.Distance(gameObject.transform.position, player.transform.position) <= 6)
{
stuff.health = stuff.health + 10;
Destroy (gameObject);
solder = float.Parse(GameObject.Find("solder").GetComponent("GUIText").text) + gameObject.GetComponent("GameStats").solder;
GameObject.Find("solder").GetComponent("GUIText").text = ""+solder;
steel = float.Parse(GameObject.Find("steel").GetComponent("GUIText").text) + gameObject.GetComponent("GameStats").steel;
GameObject.Find("steel").GetComponent("GUIText").text = ""+steel;
gold = float.Parse(GameObject.Find("gold").GetComponent("GUIText").text) + gameObject.GetComponent("GameStats").gold;
GameObject.Find("gold").GetComponent("GUIText").text = ""+gold;
plastic = float.Parse(GameObject.Find("plastic").GetComponent("GUIText").text) + gameObject.GetComponent("GameStats").plastic;
GameObject.Find("plastic").GetComponent("GUIText").text = ""+plastic;
hardplastic = float.Parse(GameObject.Find("hardplastic").GetComponent("GUIText").text) + gameObject.GetComponent("GameStats").hardplastic;
GameObject.Find("hardplastic").GetComponent("GUIText").text = ""+hardplastic;
solidplastic = float.Parse(GameObject.Find("solidplastic").GetComponent("GUIText").text) + gameObject.GetComponent("GameStats").solidplastic;
GameObject.Find("solidplastic").GetComponent("GUIText").text = ""+solidplastic;
}
}
if (ii >= total) Destroy (gameObject);
}
Comment
Answer by MarkFinn · Feb 16, 2013 at 02:18 PM
Change
var stuff : Component;
to
var stuff : GameStats;
See if that fixes it for you.
Answer by 3Duk · Feb 16, 2013 at 02:38 PM
how it should have been:
var i = 0;
var ii = 0;
var mode = 0;
var stuff : GameStats;
var player : GameObject;
var asolder : GUIText;
var asteel : GUIText;
var agold : GUIText;
var aplastic : GUIText;
var ahardplastic : GUIText;
var asolidplastic : GUIText;
var stats : GameStats;
var solder : float = 0;
var steel : float = 0;
var gold : float = 0;
var plastic : float = 0;
var hardplastic : float = 0;
var solidplastic : float = 0;
var total = 0;
function Start () {
stats = gameObject.GetComponent("GameStats");
total = Random.Range(0,6000);
player = GameObject.Find("armour");
stuff = GameObject.Find("armour").GetComponent("GameStats");
var asolder = GameObject.Find("solder").GetComponent("GUIText");
var asteel = GameObject.Find("steel").GetComponent("GUIText");
var agold = GameObject.Find("gold").GetComponent("GUIText");
var aplastic = GameObject.Find("plastic").GetComponent("GUIText");
var ahardplastic = GameObject.Find("hardplastic").GetComponent("GUIText");
var asolidplastic = GameObject.Find("solidplastic").GetComponent("GUIText");
}
function Update() {
i++;
ii++;
if (i >= 50) {
i = 0;
gameObject.transform.LookAt(player.transform);
if (Vector3.Distance(gameObject.transform.position, player.transform.position) <= 6)
{
stuff.health = stuff.health + 10;
Destroy (gameObject);
solder = float.Parse(asolder.text) + stats.solder;
asteel.text = ""+solder;
steel = float.Parse(agold.text) + stats.steel;
asteel.text = ""+steel;
gold = float.Parse(agold.text) + stats.gold;
agold.text = ""+gold;
plastic = float.Parse(aplastic.text) + stats.plastic;
aplastic.text = ""+plastic;
hardplastic = float.Parse(ahardplastic.text) + stats.hardplastic;
ahardplastic.text = ""+hardplastic;
solidplastic = float.Parse(asolidplastic.text) + stats.solidplastic;
asolidplastic.text = ""+solidplastic;
}
}
if (ii >= total) Destroy (gameObject);
}
Your answer
Follow this Question
Related Questions
MonoBehaviour.OnApplicationQuit() can not be called on Android or iOS devices 1 Answer
Is it possible to check if the touchscreen keyboard has been closed? 0 Answers
Script Runs Fine in Editor But Not on Android 0 Answers
Unity5 build options Internet Access setting 0 Answers
anti-alising texture issue 0 Answers