Hi everybody, I’ve got some problematics issues with some scripts.
In fact, I’ld like to make my Player, when he collides with some Enemy, to take damage.
I’ve got those scripts, one for GameManager :
using UnityEngine;
using System.Collections;
public class GameManager : MonoBehaviour {
//Vie du joueur//
public Texture playersHealthTexture;
//Position sur l’écran de la vie du héros//
public float positiondecranX;
public float positiondecranY;
//Taille de la vie du héros//
public int tailledeliconeX = 25;
public int tailledeliconeY = 25;
//Vie de départ//
public int playersHealth = 3;
void OnGUI(){
//Controle la vie du joueur//
for(int h = 0; h < playersHealth; h++){
GUI.DrawTexture(new Rect(positiondecranX + (h * tailledeliconeX), positiondecranX,tailledeliconeX,tailledeliconeY),VieHéros,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);
}
(Sorry for french )
And in my enemy I’ve got :
using UnityEngine;
using System.Collections;
public class MonsterDamage : MonoBehaviour {
public GameManager gameMananger;
int damageValue = 1;
void OnTriggerEnter(Collider col){
if(col.gameObject.tag == “Player”){
gameMananger.SendMessage(“PlayerDamaged”, damageValue, SendMessageOptions.DontRequireReceiver);
}
}
}
Could you help me ?