Atack in long distance with enemy

Guys i need help!

I would like my enemy to attack long distance (rande), so his attack animation would be activated and he would use the language to hit the player, so I need two things I could not find

  • he looks at the character (player) and perform the attack after a while
  • and that the collider of the language grew along with the tongue to reach the rande of attack

Ps :. before he attacked melee, he walked and attacked, only now he is fixed on the ground and only the language moves.

I’m sending his atack script …

I need help until Tuesday !!!


using UnityEngine;
using System.Collections;

namespace CompleteProject
{
public class EnemyAttack : MonoBehaviour
{
public float timeBetweenAttacks = 0.5f; // The time in seconds between each attack.
public int attackDamage = 10; // The amount of health taken away per attack.

Animator anim; // Reference to the animator component.
GameObject player; // Reference to the player GameObject.
PlayerHealth playerHealth; // Reference to the player’s health.
EnemyHealth enemyHealth; // Reference to this enemy’s health.
bool playerInRange; // Whether player is within the trigger collider and can be attacked.
float timer; // Timer for counting up to the next attack.

void Awake ()
{
// Setting up the references.
player = GameObject.FindGameObjectWithTag (“Player”);
playerHealth = player.GetComponent ();
enemyHealth = GetComponent();
anim = GetComponent ();
}

void OnTriggerEnter (Collider other)
{
// If the entering collider is the player…
if(other.gameObject == player)
{
// … the player is in range.
playerInRange = true;
bool atack;

}
}

void OnTriggerExit (Collider other)
{
// If the exiting collider is the player…
if(other.gameObject == player)
{
// … the player is no longer in range.
playerInRange = false;
anim.SetTrigger(“move”);
}
}

void Update ()
{
// Add the time since Update was last called to the timer.
timer += Time.deltaTime;

// If the timer exceeds the time between attacks, the player is in range and this enemy is alive…
if(timer >= timeBetweenAttacks && playerInRange && enemyHealth.currentHealth > 0)
{
// … attack.
Attack ();
}

// If the player has zero or less health…
if(playerHealth.currentHealth <= 0)
{
// … tell the animator the player is dead.
anim.SetTrigger (“PlayerDead”);
}
}

void Attack ()
{
// Reset the timer.
timer = 0f;

// If the player has health to lose…
if(playerHealth.currentHealth > 0)
{
// … damage the player.
playerHealth.TakeDamage (attackDamage);
}
}
}
}

Please use code tags .

using UnityEngine;
using System.Collections;

namespace CompleteProject
{
public class EnemyAttack : MonoBehaviour
{
public float timeBetweenAttacks = 0.5f; // The time in seconds between each attack.
public int attackDamage = 10; // The amount of health taken away per attack.



Animator anim; // Reference to the animator component.
GameObject player; // Reference to the player GameObject.
PlayerHealth playerHealth; // Reference to the player's health.
EnemyHealth enemyHealth; // Reference to this enemy's health.
bool playerInRange; // Whether player is within the trigger collider and can be attacked.
float timer; // Timer for counting up to the next attack.


void Awake ()
{
// Setting up the references.
player = GameObject.FindGameObjectWithTag ("Player");
playerHealth = player.GetComponent <PlayerHealth> ();
enemyHealth = GetComponent<EnemyHealth>();
anim = GetComponent <Animator> ();
}


void OnTriggerEnter (Collider other)
{
// If the entering collider is the player...
if(other.gameObject == player)
{
// ... the player is in range.
playerInRange = true;
bool atack;

}
}


void OnTriggerExit (Collider other)
{
// If the exiting collider is the player...
if(other.gameObject == player)
{
// ... the player is no longer in range.
playerInRange = false;
anim.SetTrigger("move");
}
}


void Update ()
{
// Add the time since Update was last called to the timer.
timer += Time.deltaTime;

// If the timer exceeds the time between attacks, the player is in range and this enemy is alive...
if(timer >= timeBetweenAttacks && playerInRange && enemyHealth.currentHealth > 0)
{
// ... attack.
Attack ();
}

// If the player has zero or less health...
if(playerHealth.currentHealth <= 0)
{
// ... tell the animator the player is dead.
anim.SetTrigger ("PlayerDead");
}
}


void Attack ()
{
// Reset the timer.
timer = 0f;

// If the player has health to lose...
if(playerHealth.currentHealth > 0)
{
// ... damage the player.
playerHealth.TakeDamage (attackDamage);
}
}
}
}

Uhh, what?

Tongue reach? Language move?

It may be my lack of English, but… What?

yes that’s right, a tongue stretches and attacks the player