Hi, so in the game I’m creating this script is attached to my enemy. The problem I’m having is with my attack animation “bash” attached to this object. When the player is in attacking range he attacks, but when the player moves out of range during “bash” he continues to move forward via NavMeshAgent, so I need for him to remain still while “bash” is being played. Here is the script:
using UnityEngine;
using UnityEngine.AI;
using UnityEngine;
using UnityEngine.AI;
using System.Collections;
public class Experimental : MonoBehaviour
{
public Transform player;
static Animator anim;
static AnimationClip bashClip;
bool stop;
// Use this for initialization
void Start ()
{
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update ()
{
NavMeshAgent agent = GetComponent<NavMeshAgent>();
if(Vector3.Distance(player.position, this.transform.position) > 2)
{
//check if "bash" is playing...
{
//if it is... wait for for "bash" to stop
{
//then
}
}
//otherwise if "bash" isn't playing do...
{
}
}
if(Vector3.Distance(player.position, this.transform.position) <= 2)
{
anim.SetBool ("bash", true);
anim.SetBool ("walk", false);
GetComponent <NavMeshAgent> ().enabled = false;
}
}
}
So when the player exits the attacking range, I need to
-
check if “bash” is playing
-
if it is playing, wait for it to end
-
then set bool “walk” to true
-
otherwise if it isn’t playing already, then set bool “walk” to true
if(Vector3.Distance(player.position, this.transform.position) > 2)
{
//check if “bash” is playing…
{
//if it is… wait for for “bash” to stop
{
//then do something
}
}
//otherwise if “bash” isn’t playing do…
{} }
How can I write this up in C#?
Thanks