- Home /
how to make AI reduce PlayerHealth ??
Can anyone give me a script to make the A.I reduce the Player's Health??
this is my health script
PlayerHealth JS script
static var curHealth : int = 100;
static var maxHealth : int = 100;
var healthtext : GUIText;
static var curXp : int = 0;
static var maxXp : int = 500;
var xptext : GUIText;
var level :int = 1;
static var minAttack : int = 10;
static var maxAttack : int = 50;
static var attackPower : int = 2;
function Start () {
healthRegen();
}
function Update () {
healthtext.text = curHealth + " / " + maxHealth;
xptext.text = "Level " + level + " xp " + curXp + " / " +maxXp;
if(curXp == maxXp) {
levelUpSystem();
}
if(curHealth < 0 ) {
curHealth = 0;
}
if(curHealth > maxHealth) {
curHealth = maxHealth;
}
if(Input.GetKeyDown("e")) {
curHealth -= 10;
}
if(Input.GetKeyDown("r")) {
curXp += 10;
}
}
function healthRegen () {
for(i=1;i>0;i++) {
yield WaitForSeconds(0.5);
if(curHealth < maxHealth) {
curHealth++;
}
}
}
function levelUpSystem () {
curXp = 0;
maxXp = maxXp + 50;
level++;
maxHealth += 50;
}
========================================================================================= //
I try with This script ,BUT not work
var cube : GameObject;
function Awake()
{
cube = gameObject.FindWithTag("Player");
}
function OnCollisionEnter(hit : Collision)
{
if(hit.gameObject.tag == "cube")
PlayerHealth.curHealth -= 20;
}
========================================================================================= //
Please Assist :)
hi i dont think i can read your script to fix this go to edit>select the code and press 101010 .by the way are you trying to reduce player health when you press a button
@danish114206 Are you trying to reduce the Health of the player on button press(just spitballing) .Explain what you are trying to achieve so that i can post the script
Your answer
Follow this Question
Related Questions
player to kill ai 0 Answers
NavMesh flee. Ai flee from player. 4 Answers
Need Help About Health,Damage 1 Answer
Script is only working on original object 2 Answers
Player Health 3 Answers