本文整理汇总了C#中EnemyState类的典型用法代码示例。如果您正苦于以下问题:C# EnemyState类的具体用法?C# EnemyState怎么用?C# EnemyState使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EnemyState类属于命名空间,在下文中一共展示了EnemyState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Awake
// Use this for initialization
void Awake()
{
body = gameObject.GetComponent<Rigidbody2D> ();
player = GameObject.FindGameObjectWithTag("Player").transform;
enemyState = EnemyState.Chase;
spriteRenderer = gameObject.GetComponent<SpriteRenderer> ();
}
示例2: Update
/*In here there is a switch-statement which handles which method that is going
* to be updating, this is chosen by the currentState of the enemy.
It is in here that you will add your own EnemyState.yourState-case and call for your own method below*/
public virtual void Update()
{
playerPosition = (GameObject.Find ("Player").transform.position);
distance = Vector3.Distance(playerPosition, transform.position);
switch (currentState) {
case EnemyState.initializing:
/*filling in the player reference for easier access*/
/*playerReference = GameObject.Find ("Player");*/
currentState = EnemyState.idle;
break;
case EnemyState.idle:
Idle();
break;
case EnemyState.sawPlayer:
SawPlayer();
break;
case EnemyState.chasing:
Chasing();
break;
case EnemyState.attacking:
Attacking();
currentState = EnemyState.idle;
break;
case EnemyState.fleeing:
Fleeing();
currentState = EnemyState.idle;
break;
default:
break;
}
}
示例3: CheckState
void CheckState()
{
if( bKnockBack )
{
state = EnemyState.KnockBack;
}
else if( !bKnockBack && state == EnemyState.KnockBack)
{
state = EnemyState.Idle;
}
if( fAttackCurrent > fAttackTime + (fAttackWait*2) )
{
fAttackCurrent = 0;
state = EnemyState.Idle;
attack.SetActive(false);
}
else if( bAttacked != true && (state == EnemyState.Attack || ( state != EnemyState.Attack && Vector3.Distance( transform.position , manager.GetActivePlayer().transform.position ) < fAttackDistance) ) )
{
state = EnemyState.Attack;
}
if( state != EnemyState.KnockBack && state != EnemyState.Dead && state != EnemyState.Attack)
{
state = EnemyState.Move;
}
else if( state == EnemyState.Dead)
{
Die();
}
// else
// {
// state = EnemyState.Idle;
// }
}
示例4: FixedUpdate
void FixedUpdate()
{
GetComponent<Animator>().SetBool("IsAttacking", false);
switch (State)
{
case EnemyState.Idle:
if (CanSeePlayer())
{
State = EnemyState.Detect;
GetComponent<Animator>().SetBool("IsMoving", true);
}
break;
case EnemyState.Patrolling:
if (CanSeePlayer())
{
State = EnemyState.Detect;
GetComponent<Animator>().SetBool("IsMoving", true);
}
break;
case EnemyState.Searching:
SearchState();
break;
case EnemyState.Detect:
AlertState();
break;
}
}
示例5: FixedUpdate
// Update is called once per frame
void FixedUpdate()
{
if (Cutscene.current != null) return;
if (state == EnemyState.Patrolling) {
// Reverse direction if at destination
if ((Vector2)transform.position == patrolEnd) {
Vector3 temp = patrolEnd;
patrolEnd = patrolStart;
patrolStart = temp;
}
transform.position = Vector2.MoveTowards(transform.position, patrolEnd, runSpeed * Time.deltaTime);
if (canFollow) {
if (Vector2.Distance(Player.S.transform.position, transform.position) < sightRange)
state = EnemyState.Following;
}
} else if (state == EnemyState.Following) {
transform.position = Vector2.MoveTowards(transform.position, Player.S.transform.position, followSpeed * Time.deltaTime);
if (Vector2.Distance(Player.S.transform.position, transform.position) > sightRange)
state = EnemyState.Patrolling;
}
if (Vector2.Distance(Player.S.transform.position, transform.position) < attackRange) {
if (Time.time > nextAttackTime) {
Player.S.TakeDamage(attackDamage);
nextAttackTime = Time.time + attackSpeed;
}
}
}
示例6: Update
/// <summary>
/// Updates this enemy instance
/// </summary>
/// <param name="gameTime">The time elapsed since the last update</param>
public override void Update(GameTime gameTime)
{
switch (_state)
{
case EnemyState.Entering:
if (Entering(gameTime))
{
_state = EnemyState.Attacking;
this.Velocity = (this.Position.X < ManicShooter.ScreenSize.Width / 2) ? new Vector2(_maxSpeed, 0) : new Vector2(-_maxSpeed, 0);
}
break;
case EnemyState.Attacking:
if (HorizontalPasses(gameTime)) _state = EnemyState.Leaving;
break;
case EnemyState.Leaving:
LeaveScreen(gameTime.ElapsedGameTime);
if (this.IsOffScreen()) this.Destroy();
break;
}
ApplyVelocity(gameTime.ElapsedGameTime);
UpdateWeaponPositions();
base.Update(gameTime);
}
示例7: Initialize
private void Initialize(Vector2 entryPosition)
{
this.ScaleSize(0.5M);
this.Visible = true;
this.randomDropChance = 10;
_maxSpeed = 150;
_state = EnemyState.Entering;
this.targetEntryPosition = entryPosition;
this.exitPosition = new Vector2(-50, -50);
this._maxShotTime = 1000;
this._shotTimer = this._maxShotTime;
this._shotCount = 0;
this._lastPlayerPositions = new Queue<Vector2>();
this._lifeTimer = 10000;
this.Velocity = Vector2.Zero;
_weapons = new List<IWeapon>();
//Point pellet gun
_weapons.Add(new PelletGun(this.centerPosition, new Vector2(0, this.Height / 2), new Vector2(0, 250), 300d));
}
示例8: Reset
public void Reset()
{
state = EnemyState.Idle;
gs.Enemy.width = 100f;
gs.Enemy.height = 160f;
gs.Enemy.position = gs.startEnemyPos;
}
示例9: Start
void Start () {
player = GameManager.instance.Player;
spiral = new SpiralMotionEnemyState(this, player);
currentState = spiral;
currentState.StartState();
}
示例10: Die
public void Die()
{
currentState = EnemyState.DEAD;
isDead = true;
audio.PlayDie();
StartCoroutine(DieCoroutine());
}
示例11: StopMoving
public void StopMoving(){
Animation ani = gameObject.GetComponent<Animation> ();
if(ani){
//ani.Stop();
STATE = EnemyState.Stop;
}
}
示例12: SetState
public void SetState(EnemyState state)
{
this.state = state;
switch (state)
{
case EnemyState.IDLE:
GetComponent<Animator>().SetBool("isHit", false);
GetComponent<Animator>().SetBool("isKnock", false);
transform.localScale = new Vector3(1, 1, 1);
break;
case EnemyState.HIT:
GetComponent<Animator>().SetBool("isHit", true);
if (attack)
attack.Play();
break;
case EnemyState.KNOCK:
GetComponent<Animator>().SetBool("isKnock", true);
transform.localScale = new Vector3(-1, 1, 1);
if (attack)
attack.Play();
break;
case EnemyState.DEAD:
GetComponent<Animator>().SetBool("isDead", true);
GetComponent<TargetState>().IsDead = true;
if (die)
die.Play();
break;
}
}
示例13: Enemy
public Enemy(Texture2D loadedTexture, Vector2 position, int frameCount, int framesPerSec, Action<Enemy, double> ai)
: base(loadedTexture, position, 0f, 1f, 1f, frameCount, framesPerSec)
{
this.Ai = ai;
this.State = EnemyState.Idle;
this.Direction = Directions.Left;
}
示例14: Die
public void Die()
{
ES = EnemyState.Dead;
anim.CrossFade("Dead", 0.2f);
//fade out and destroy?
StartCoroutine("FadeOut");
}
示例15: InitializeDefaultEnemy
private void InitializeDefaultEnemy(Vector2 TargetEntryPoint)
{
this.ScaleSize(0.5M);
_screenPasses = 0;
_maxPasses = 3;
this.Visible = true;
_maxSpeed = 150;
_state = EnemyState.Entering;
this.targetEntryPoint = TargetEntryPoint;
this.Velocity = Vector2.Zero;
_weapons = new List<IWeapon>();
//Top Left pellet gun
_weapons.Add(new PelletGun(this.centerPosition, new Vector2(-this.Width / 2, -this.Height / 2), new Vector2(-250, -250), 300d));
//Top Right pellet gun
_weapons.Add(new PelletGun(this.centerPosition, new Vector2(this.Width / 2, -this.Height / 2), new Vector2(250, -250), 300d));
//Bottom Left pellet gun
_weapons.Add(new PelletGun(this.centerPosition, new Vector2(-this.Width / 2, this.Height / 2), new Vector2(-250, 250), 300d));
//Bottom Right pellet gun
_weapons.Add(new PelletGun(this.centerPosition, new Vector2(this.Width / 2, this.Height / 2), new Vector2(250, 250), 300d));
}