i am newer to Unity but far from new to programming. I am trying to check (and reset if the scenario arises) the current position of a character. I have checked numerous boards and the problem is always that someone spelled GameObject gameObject and I am confident that is not the problem… any ideas?
#pragma strict
private var health : int = 0;
var maxHealth : int = 10;
private var isDead : boolean = false;
//var playerPos : Vector3 = playerObject.transform.position;
//set the players current health to a new value, if a negative is input then
//default the health to 0.
function setHealth(health : int) {
if (health <= 0) {
this.health = health;
}
else if (health >= maxHealth) {
this.health = maxHealth;
}
}
function Reset() {
GameObject.Transform.x = 11.38105;
GameObject.Transform.y = 0.8;
GameObject.Transform.z = -1.680236;
}
function update() {
if (this.health == 0) {
this.isDead = true;
}
if (gameObject.transform.y <= 0) {
this.isDead = true;
}
if (this.isDead == true) {
Reset(gameObject);
}
}
Thanks
‘GameObject’ is the class. ‘gameObject’ is this specific instance. ‘Transform’ is the class. ‘transform’ is this specific instance of the class. In addition, ‘x’ is part of a Vector3 (position), not a transform. You can do ‘gameObject.transform.position.x’, but you can shortcut it to transform.position.x. So:
#pragma strict
private var health : int = 0;
var maxHealth : int = 10;
private var isDead : boolean = false;
//var playerPos : Vector3 = playerObject.transform.position;
//set the players current health to a new value, if a negative is input then
//default the health to 0.
function setHealth(health : int) {
if (health <= 0) {
this.health = health;
}
else if (health >= maxHealth) {
this.health = maxHealth;
}
}
function Reset() {
transform.position.x = 11.38105;
transform.position.y = 0.8;
transform.position.z = -1.680236;
}
function Update() {
if (this.health == 0) {
this.isDead = true;
}
if (transform.position.y <= 0) {
this.isDead = true;
}
if (this.isDead == true) {
Reset();
}
}