wandering implemented
This commit is contained in:
@@ -11,7 +11,7 @@ public class SlimeAI : MonoBehaviour
|
||||
GameObject player;
|
||||
int HP;
|
||||
|
||||
public float moveSpeed = 3f;
|
||||
public float moveSpeed = 4f;
|
||||
public float rotSpeed = 100f;
|
||||
|
||||
private bool isWandering = false;
|
||||
@@ -28,6 +28,7 @@ public class SlimeAI : MonoBehaviour
|
||||
animator = GetComponent<Animator>();
|
||||
player = GameObject.FindWithTag("Player");
|
||||
HP = 10;
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@@ -36,6 +37,7 @@ public class SlimeAI : MonoBehaviour
|
||||
playerDistance = Vector3.Distance(player.transform.position, transform.position);
|
||||
if (playerDistance < 1.5) //Attack
|
||||
{
|
||||
animator.SetBool("Wandering", false);
|
||||
animator.SetBool("EnemyInAttackRange", true);
|
||||
animator.SetBool("EnemyInAggroRange", true);
|
||||
animator.SetBool("EnemyInVisionRange", true);
|
||||
@@ -43,6 +45,7 @@ public class SlimeAI : MonoBehaviour
|
||||
}
|
||||
else if (playerDistance < 10) //Chase
|
||||
{
|
||||
animator.SetBool("Wandering", false);
|
||||
animator.SetBool("EnemyInAttackRange", false);
|
||||
animator.SetBool("EnemyInAggroRange", true);
|
||||
animator.SetBool("EnemyInVisionRange", true);
|
||||
@@ -51,33 +54,42 @@ public class SlimeAI : MonoBehaviour
|
||||
}
|
||||
else if (playerDistance < 18) //Stare
|
||||
{
|
||||
animator.SetBool("Wandering", false);
|
||||
animator.SetBool("EnemyInAttackRange", false);
|
||||
animator.SetBool("EnemyInAggroRange", false);
|
||||
animator.SetBool("EnemyInVisionRange", true);
|
||||
Rotate();
|
||||
StopCoroutine("Wandering");
|
||||
}
|
||||
else //Idle
|
||||
else
|
||||
{
|
||||
animator.SetBool("EnemyInAttackRange", false);
|
||||
animator.SetBool("EnemyInAggroRange", false);
|
||||
animator.SetBool("EnemyInVisionRange", false);
|
||||
}
|
||||
|
||||
if (!isWandering)
|
||||
{
|
||||
//Idle
|
||||
StartCoroutine("Wander");
|
||||
|
||||
if (isRotatingRight == true)
|
||||
{
|
||||
gameObject.GetComponent<Animator>().Play("IdleNormal");
|
||||
transform.Rotate(transform.up * Time.deltaTime * rotSpeed);
|
||||
}
|
||||
if (isRotatingLeft == true)
|
||||
{
|
||||
gameObject.GetComponent<Animator>().Play("IdleNormal");
|
||||
transform.Rotate(transform.up * Time.deltaTime * -rotSpeed);
|
||||
}
|
||||
if (isWalking == true)
|
||||
{
|
||||
gameObject.GetComponent<Animator>().Play("WalkFWD");
|
||||
transform.position += transform.forward * moveSpeed * Time.deltaTime;
|
||||
}
|
||||
}
|
||||
Debug.Log(isWandering);
|
||||
Debug.Log(isRotatingLeft);
|
||||
Debug.Log(isRotatingRight);
|
||||
if (isRotatingRight == true)
|
||||
{
|
||||
animator.SetBool("Wandering", false);
|
||||
transform.Rotate(transform.up * Time.deltaTime * rotSpeed);
|
||||
}
|
||||
if (isRotatingLeft == true)
|
||||
{
|
||||
animator.SetBool("Wandering", false);
|
||||
transform.Rotate(transform.up * Time.deltaTime * -rotSpeed);
|
||||
}
|
||||
if (isWalking == true)
|
||||
{
|
||||
animator.SetBool("Wandering", true);
|
||||
transform.position += transform.forward * moveSpeed * Time.deltaTime;
|
||||
}
|
||||
if (HP <= 0)
|
||||
{
|
||||
@@ -112,10 +124,10 @@ public class SlimeAI : MonoBehaviour
|
||||
IEnumerator Wander()
|
||||
{
|
||||
int rotTime = Random.Range(1, 3);
|
||||
int rotateWait = Random.Range(1, 4);
|
||||
int rotateWait = Random.Range(1, 5);
|
||||
int rotateLorR = Random.Range(1, 2);
|
||||
int walkWait = Random.Range(1, 5);
|
||||
int walkTime = Random.Range(1, 6);
|
||||
int walkTime = Random.Range(1, 20);
|
||||
|
||||
isWandering = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user