GameManager.cs
using UnityEngine;
using System.Collections;
public class GameManager : MonoBehaviour {
//Player Life
public Texture playersHealthTexture;
//Control Screen Position of Texture
public float screenPositionX;
public float screenPositionY;
//Controls Icon Size on Screen
public float iconSizeX = 25;
public float iconSizeY = 25;
//Starting lives
public int playersHealth = 5;
void OnGUI(){
//Controls Players Health Textures
for(int h = 0; h < playersHealth; h++){
GUI.DrawTexture(new Rect(screenPositionX + (h * iconSizeX), screenPositionY, iconSizeX, iconSizeY), playersHealthTexture,ScaleMode.ScaleToFit, true, 0);
}
}
void PlayerDamaged(int damage){
if (playersHealth > 0) {
playersHealth -= damage;
}
if(playersHealth <= 0){
playersHealth = 0;
RestartScene();
}
}
void RestartScene(){
Application.LoadLevel(Application.loadedLevel);
}
}
Enemy.js
#pragma strict
private var fall : boolean;
var Player : GameObject;
var spawnPoint : Transform;
var stomp : boolean;
function Update () {
if(stomp){
transform.position.z = 4;
transform.localScale.y /= 2;
fall = true;
gameObject.GetComponent(PlatformMover).step = 0.0;
stomp = false;
}
if(fall){
transform.position.y -= 0.05;
}
if(transform.position.y < -25){
Destroy(gameObject);
}
}
function OnTriggerEnter(other : Collider){
if(!stomp){
if(other.tag == "Player"){
Destroy(other.gameObject);
var P : GameObject = Instantiate(Player, spawnPoint.position, Quaternion.identity);
var sf = Camera.main.GetComponent(SmoothFollow2);
sf.target = P.transform;
}
}
}
ok so far i have my health bar showing But i
need it to subtract 1 out of 5 hearts every time
the enemy kills my player.
Can someone help me out with finishing that code and show me where to put it?