Stop object from moving

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

You are going to want to do something like this. I don’t know exactly where you want the if statement but if you check if he is currently bashing then he won’t update. You likely want to wrap the rotation logic in this if statement. You also would need to negate it but I think you get the point hopefully :slight_smile: if not, comment back.

if (anim.GetBool("bash")) 
{
  // Basically do nothing
  return;
}