Exemplo n.º 1
0
	// Update is called once per frame
	void Update () {

		if (attackCooldown > 0) {
			attackCooldown -= Time.fixedDeltaTime;
		}

		if (target) {
			vectorToTarget = target.position - transform.position;
		}

		//player attacks if in range and cooldown is off. 
		if (attackCooldown <= 0 && vectorToTarget.magnitude <= 2.2 && Enemy) {
			
			enemyAttack.AIAttack ();
			attackCooldown = attackCooldownTime;
			transform.position += transform.up * -moveSpeed * Time.deltaTime;

		} else if (vectorToTarget.magnitude > 2.5 && vectorToTarget.magnitude < 15 && target) {

			////////////Animation chase start/////////////a
				animate.SetBool ("Run", true);
			/////////////////////////////////

			Quaternion rotation = Quaternion.LookRotation
				(target.transform.position - transform.position, transform.TransformDirection (Vector3.forward));
			float rot = Mathf.Atan2 (vectorToTarget.y, vectorToTarget.x) * Mathf.Rad2Deg;

			//rotate to face player
			transform.rotation = Quaternion.Euler (0, 0, rot - 90);

			//move towwards the "player"
			transform.position += transform.up * moveSpeed * Time.deltaTime;




		} else {
			//////annimationstop
			//animate.SetBool ("Run", false);
		} 
	}