void IdleState() { //Idle Behaviour if ( Vector3.Distance(this.transform.position, origin) > 10) navAgent.SetDestination (origin); else anim.Play("Wait"); //Transistion to ChaseState if (player != null) { if (Vector3.Distance (this.transform.position, player.transform.position) < 30) currentState = blobState.Chase; } else { if (player == null) { player = GameObject.FindGameObjectWithTag ("Player"); } else Debug.LogError ("NO player"); if (player != null) { playerScript = player.GetComponent("PlayerScript") as PlayerScript; } } }
void ChaseState() { //Chase Behaviour if (player != null) navAgent.SetDestination (player.transform.position); if (!anim.IsPlaying ("Walk") && !anim.IsPlaying ("Damage")) anim.Play ("Walk"); //Transition to Idle if (player != null) { if (Vector3.Distance (this.transform.position, player.transform.position) > 60) currentState = blobState.Idle; } else { if (player == null) { player = GameObject.FindGameObjectWithTag ("Player"); } else Debug.LogError ("NO player"); if (player != null) { playerScript = player.GetComponent("PlayerScript") as PlayerScript; } } }
// Use this for initialization void Start() { currentHitPoints = baseHitPoints; anim = GetComponent<Animation>(); navAgent = GetComponent<NavMeshAgent>(); currentState = blobState.Idle; origin = this.transform.position; if (player == null) { player = GameObject.FindGameObjectWithTag ("Player"); } else Debug.LogError ("NO player"); if (player != null) { playerScript = player.GetComponent("PlayerScript") as PlayerScript; } }
void OnTriggerEnter(Collider other) { if (currentState != blobState.Dead) { if (other.gameObject.tag == "Sword") { if (playerScript.attacking){ anim.Play ("Damage"); baseHitPoints--; if (baseHitPoints <= 0) { currentState = blobState.Dead; } } } } }