private void Awake() { enemy = GetComponent <Enemy>(); anim = GetComponent <Animator>(); enemyIdleState = new EnemyIdleState(this); enemyWalkState = new EnemyWalkState(this); enemyRangeAttackState = new EnemyRangeAttackState(this); enemyMeleeAttackState = new EnemyMeleeAttackState(this); enemyMagicAttackState = new EnemyMagicAttackState(this); enemyBombAttackState = new EnemyBombAttackState(this); enemyFreezeState = new EnemyFreezeState(this); enemyDieState = new EnemyDieState(this); isWaiting = false; }
// Update is called once per frame void Update() { waitTime_ += Time.deltaTime; if (waitTime_ >= 3.0f) { int range = Random.Range(0, 100); Object.Destroy(GetComponent <BaseEnemy>().State); if (range < 50) { if (range > 25) { EnemyWalkState walk = gameObject.AddComponent <EnemyWalkState>(); walk.GoalPosition = goalPost_.transform; GetComponent <BaseEnemy>().State = walk; GetComponent <BaseEnemy>().Animation.Walk = true; } else { Link[] link = GameObject.Find("FieldObject/Post").GetComponent <PostManager>().Link; EnemyWaitPostState walk = gameObject.AddComponent <EnemyWaitPostState>(); walk.IndexGoal = Random.Range(0, link.Length - 1); GetComponent <BaseEnemy>().State = walk; GetComponent <BaseEnemy>().Animation.Walk = true; } } else { if (range < 75) { GetComponent <BaseEnemy>().State = gameObject.AddComponent <EnemyAttackState>(); GetComponent <BaseEnemy>().Animation.Attack = true; } else { Link[] link = GameObject.Find("FieldObject/Post").GetComponent <PostManager>().Link; EnemyWaitPostState walk = gameObject.AddComponent <EnemyWaitPostState>(); walk.IndexGoal = Random.Range(0, link.Length - 1); GetComponent <BaseEnemy>().State = walk; GetComponent <BaseEnemy>().Animation.Walk = true; } } } }