This really seems like it should make sense, and work, but clearly I’m missing something:
I’m trying to implement a basic combat system based on Jesse Etzler’s tutorial on Youtube: link text However, I can’t get it to work. In a nutshell I place a cube over the Player and make a label called “attack Area.” Then I place the script from below on my enemy. The theory is that when the enemy enters the attack Area, the player pressing 1 will deal damage to them. Only, that’s not happening. I truly do want to learn what I’m doing wrong here, and not just be a leech on people’s knowledge. Have spent time reading up on tutorials, trying other scripts, searching on google, and I just don’t get what I’m missing. The thing that stinks is the video tutorial makes this make perfect sense, but when I implement it, nothing works.
var enemyHealth : int = 100;
function Update () {
if(this.enemyHealth <= 0) {
playerHealth.curXp += 10;
Destroy(this.gameObject);
}
}
function OnTriggerStay (col : Collider) {
if(col.gameObject.tag == "attackArea") {
if(Input.GetKeyDown("1")) {
this.enemyHealth -=100;
}
}
}
I can walk up to the enemy and swing away, with no effect. I have the attack script attached to them, the attack area tagged and attached to the player, and nothing. Any help, guidance, stinging criticism is greatly appreciated. God bless.
(Below, in case it needs to be referenced is the playerhealth script)
var curHealth : int = 35;
var maxHealth : int = 35;
var healthtext : GUIText;
static var curXp : int = 0;
var maxXp : int = 100;
var xptext : GUIText;
var level : int = 1;
function Start ()
{
healthRegen();
}
function Update ()
{
healthtext.text = curHealth + "hp / " + maxHealth;
xptext.text = "Level " + level + " XP " + curXp + " / " + maxXp;
if(curXp == maxXp)
{
levelUpSystem();
}
if(curHealth <= 0 )
{
curHealth = 0;
Application.LoadLevel(2);
}
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(5.0);
if(curHealth < maxHealth)
{
curHealth++;
}
}
}
function levelUpSystem ()
{
curXp = 0;
maxXp = maxXp + 50;
maxHealth += 15;
level++;
}