I have a script attached to my enemy robot where he follows me and then attacks when he gets close enough. The script works fine, though when he is attacking he’s still moving forward (z-axis), so I need him to stop moving and rotating when attacking. Here is the script:
using UnityEngine;
using System.Collections;
public class CharacterPursueYbot : MonoBehaviour {
public Transform player;
static Animator anim;
// Use this for initialization
void Start ()
{
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update ()
{
if(Vector3.Distance(player.position, this.transform.position) < 100)
{
Vector3 direction = player.position - this.transform.position;
direction.y = 0;
this.transform.rotation = Quaternion.Slerp (this.transform.rotation,
Quaternion.LookRotation (direction), 0.1f);
anim.SetBool ("isIdle", false);
if (direction.magnitude > 2)
{
this.transform.Translate (0, 0, 0.05f);
anim.SetBool ("injuredWalk", true);
anim.SetBool ("bash", false);
}
else
{
// STOP MOVING AND ROTATING STATEMENT HERE
anim.SetBool ("bash", true);
anim.SetBool ("injuredWalk", false);
}
}
else
{
anim.SetBool ("isIdle", true);
anim.SetBool ("injuredWalk", false);
anim.SetBool ("bash", false);
}
}
}
I need him to stop moving and rotating in my direction when;
// STOP MOVING AND ROTATING STATEMENT HERE
anim.SetBool ("bash", true);
anim.SetBool ("injuredWalk", false);
So basically, when he is attacking i need him to stop moving and rotating.
How should I go about this?
THANKS