- Home /
BurgZergArcade tutorial 5 problem
I have been following the BurgZergArcade tutorials for making a Hack n Slash game. I'm on tutorial number 5, "Unity3d tutorial - Melee 1/3. I have copied all the code he wrote exactly, and there are no errors, but when I click the "F" key nothing happens. After some research I've noticed its a common problem, but i found no answers. Can someone please help me?
PlayerAttack.cs Code:
using UnityEngine;
using System.Collections;
public class PlayerAttack : MonoBehaviour {
public GameObject target;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKeyUp(KeyCode.F)) {
Attack();
}
}
private void Attack() {
float distance = Vector3.Distance(target.transform.position, transform.position);
Debug.Log (distance);
if(distance < 2.5f) {
EnemyHealth eh = (EnemyHealth)target.GetComponent("EnemyHealth");
eh.AddjustCurrentHealth(-10);
}
}
}
Code from where you check for the key press would be good. Please edit your question when you post the code and indent it before you paste by 4 spaces or 1 tab
So you mean the enemy health doesn't reduce? Because you aren't doing anything else like playing an animation or anything so not much will happen...
Right so you have set target to somethiing? If you open the console it should be printing the distance between that target and your player - can you see that when you press the F key? Is it always more than 2.5 - because maybe you have your scale wrong or something.
Can you see any errors in that console?
Well I set it to be when u are less than 2.5 away from him, take -10 from his health, which I have a display for at the top of the screen.
Answer by OwenBay · Jun 17, 2012 at 10:00 PM
Never mind, sorry for the trouble, but after looking back through my scripts I found my blunder. I had written,
if(curHealth < maxHealth) curHealth = maxHealth;
Which of course it would be less, if I'm trying to subtract health! thanks for the help anyway.
Your answer
Follow this Question
Related Questions
Unity BurgZergArcade Tutorial 20 errors. 1 Answer
How to Turn 3D Model Into Weapon? 1 Answer
BurgZergArcade Unity tutorial 19-20 errors. 0 Answers
Melee combat help! 1 Answer
BurgZergArcade tutorial 20 errors? 0 Answers