slime wandering
This commit is contained in:
@@ -11,6 +11,14 @@ public class SlimeAI : MonoBehaviour
|
||||
GameObject player;
|
||||
int HP;
|
||||
|
||||
public float moveSpeed = 3f;
|
||||
public float rotSpeed = 100f;
|
||||
|
||||
private bool isWandering = false;
|
||||
private bool isRotatingLeft = false;
|
||||
private bool isRotatingRight = false;
|
||||
private bool isWalking = false;
|
||||
|
||||
//[SerializeField]
|
||||
//private UnityEvent onAttack;
|
||||
|
||||
@@ -33,7 +41,7 @@ public class SlimeAI : MonoBehaviour
|
||||
animator.SetBool("EnemyInVisionRange", true);
|
||||
Rotate();
|
||||
}
|
||||
else if (playerDistance < 5) //Chase
|
||||
else if (playerDistance < 10) //Chase
|
||||
{
|
||||
animator.SetBool("EnemyInAttackRange", false);
|
||||
animator.SetBool("EnemyInAggroRange", true);
|
||||
@@ -41,7 +49,7 @@ public class SlimeAI : MonoBehaviour
|
||||
Rotate();
|
||||
Move();
|
||||
}
|
||||
else if (playerDistance < 8) //Stare
|
||||
else if (playerDistance < 18) //Stare
|
||||
{
|
||||
animator.SetBool("EnemyInAttackRange", false);
|
||||
animator.SetBool("EnemyInAggroRange", false);
|
||||
@@ -53,6 +61,23 @@ public class SlimeAI : MonoBehaviour
|
||||
animator.SetBool("EnemyInAttackRange", false);
|
||||
animator.SetBool("EnemyInAggroRange", false);
|
||||
animator.SetBool("EnemyInVisionRange", false);
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (HP <= 0)
|
||||
{
|
||||
@@ -63,6 +88,8 @@ public class SlimeAI : MonoBehaviour
|
||||
print("asd");
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
void Rotate()
|
||||
{
|
||||
@@ -81,4 +108,35 @@ public class SlimeAI : MonoBehaviour
|
||||
{
|
||||
HP -= dmg;
|
||||
}
|
||||
|
||||
IEnumerator Wander()
|
||||
{
|
||||
int rotTime = Random.Range(1, 3);
|
||||
int rotateWait = Random.Range(1, 4);
|
||||
int rotateLorR = Random.Range(1, 2);
|
||||
int walkWait = Random.Range(1, 5);
|
||||
int walkTime = Random.Range(1, 6);
|
||||
|
||||
isWandering = true;
|
||||
|
||||
yield return new WaitForSeconds(walkWait);
|
||||
isWalking = true;
|
||||
yield return new WaitForSeconds(walkTime);
|
||||
isWalking = false;
|
||||
yield return new WaitForSeconds(rotateWait);
|
||||
if (rotateLorR == 1)
|
||||
{
|
||||
isRotatingRight = true;
|
||||
yield return new WaitForSeconds(rotTime);
|
||||
isRotatingRight = false;
|
||||
}
|
||||
if (rotateLorR == 2)
|
||||
{
|
||||
isRotatingLeft = true;
|
||||
yield return new WaitForSeconds(rotTime);
|
||||
isRotatingLeft = false;
|
||||
}
|
||||
isWandering = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user