Hello,
I have a spawning script for my enemies and they can attack me but I can’t attack them.
I have tried using tags but that has not worked. Could some one PLEASE help me.
My attack script is in C Sharp.
Here is my player attack script (No attack method included.):
using UnityEngine;
using System.Collections;
public class PlayerAttack : MonoBehaviour {
public GameObject target;
public float attackTimer;
public float coolDown;
public GameObject Original;
// Use this for initialization
void Start () {
attackTimer = 0;
coolDown = 0.0f;
}
// Update is called once per frame
void Update () {
There’s a couple ways you could do it. When you spawn your enemies, you could add them to an array that can give a reference to the enemy, or you could cast a ray out from the center of the player and get the game object of whatever it hits. (then you’d need to use a tag or something to make sure it’s an enemy) and get the game object from that
you could also check for the existance of a certain component at the gameobject you want to attack. do a getcomponent fe and check the reutrn value to be nonzero. then you a have a gameobject with an attack script attached.
but you need the gamobject to attack to find. look here: http://forum.unity3d.com/threads/119447-Clicking-on-an-enemy-to-target-him
Well, the spawning is is way too big to post so I’ll show you the Enemy Health if that helps…
Also, I am kinda new to scripting so I can’t understand everything, could you please try and keep it simple.
Here is the Enemy Health Script:
using UnityEngine;
using System.Collections;
public class EnemyHealth : MonoBehaviour {
public int maxHealth = 50;
public int curHealth = 50;
public float healthBarLength;
// Use this for initialization
void Start () {
healthBarLength = Screen.width / 1;
}
// Update is called once per frame
void Update () {
AddjustCurrentHealth(0);