当前位置: 首页>>代码示例>>C#>>正文


C# EnemyState类代码示例

本文整理汇总了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> ();
 }
开发者ID:klaxorx,项目名称:TrippingBalls,代码行数:8,代码来源:Enemy.cs

示例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;
        }
    }
开发者ID:Fenrigus,项目名称:JQVerticalSlice,代码行数:37,代码来源:EnemyBehaviour.cs

示例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;
        //		}
    }
开发者ID:patrick-ryan-aie,项目名称:TrickyNinja,代码行数:35,代码来源:GeneralNinjaScript.cs

示例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;
            }
        }
开发者ID:EricFreeman,项目名称:DungeonGame,代码行数:28,代码来源:EnemyMovement.cs

示例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;
            }
        }
    }
开发者ID:syogesh,项目名称:Lights,代码行数:30,代码来源:Enemy.cs

示例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);
        }
开发者ID:TheGameDevelopmentClub,项目名称:Manic-Shooter,代码行数:30,代码来源:DefaultEnemy.cs

示例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));
        }
开发者ID:TheGameDevelopmentClub,项目名称:Manic-Shooter,代码行数:28,代码来源:HunterEnemy.cs

示例8: Reset

 public void Reset()
 {
     state = EnemyState.Idle;
     gs.Enemy.width = 100f;
     gs.Enemy.height = 160f;
     gs.Enemy.position = gs.startEnemyPos;
 }
开发者ID:KogaSilverDragon,项目名称:Ludum-Dare-27,代码行数:7,代码来源:EnemyScript.cs

示例9: Start

	void Start () {
		player = GameManager.instance.Player;
		spiral = new SpiralMotionEnemyState(this, player);

		currentState = spiral;
		currentState.StartState();
	}
开发者ID:sdomenici009,项目名称:Starfield,代码行数:7,代码来源:NeutralEnemy.cs

示例10: Die

 public void Die()
 {
     currentState = EnemyState.DEAD;
     isDead = true;
     audio.PlayDie();
     StartCoroutine(DieCoroutine());
 }
开发者ID:idaelDev,项目名称:Five-At-Home-LudumDare33,代码行数:7,代码来源:Enemy.cs

示例11: StopMoving

	public void StopMoving(){
		Animation ani = gameObject.GetComponent<Animation> ();
		if(ani){
			//ani.Stop();
			STATE = EnemyState.Stop;
		}
	}
开发者ID:kyo88,项目名称:runner,代码行数:7,代码来源:ZombieController.cs

示例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;
     }
 }
开发者ID:dvsonic,项目名称:AmazingNinjia,代码行数:29,代码来源:EnemyController.cs

示例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;
 }
开发者ID:josiah1888,项目名称:game-dev,代码行数:7,代码来源:Enemy.cs

示例14: Die

 public void Die()
 {
     ES = EnemyState.Dead;
     anim.CrossFade("Dead", 0.2f);
     //fade out and destroy?
     StartCoroutine("FadeOut");
 }
开发者ID:dighjd12,项目名称:Project_Escape,代码行数:7,代码来源:Enemy.cs

示例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));
        }
开发者ID:TheGameDevelopmentClub,项目名称:Manic-Shooter,代码行数:27,代码来源:DefaultEnemy.cs


注:本文中的EnemyState类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。