public BitmapImage SetAnimation(Move move) { if (move == Move.Stop) { move = _lastMove; } switch (move) { case Move.Down: _currentEnemyFacing = EnemyFacing.Down; _lastMove = move; break; case Move.Up: _currentEnemyFacing = EnemyFacing.Up; _lastMove = move; break; case Move.Left: _currentEnemyFacing = EnemyFacing.Left; _lastMove = move; break; case Move.Right: _currentEnemyFacing = EnemyFacing.Right; _lastMove = move; break; } return(_enemyFacingBitmapImages[_currentEnemyFacing]); }
public void SearchForPlayer() { if (CheckPlayerLoc() && TimeCountdown <= 0) { TimeCountdown = TimeBetween; int dir = Random.Range(0, 3); if (dir == 0) { facing = EnemyFacing.UP; AnimateEnemyFace("enemyup"); } else if (dir == 1) { facing = EnemyFacing.DOWN; AnimateEnemyFace("enemydown"); } else if (dir == 2) { facing = EnemyFacing.LEFT; AnimateEnemyFace("enemyleft"); } else { facing = EnemyFacing.RIGHT; AnimateEnemyFace("enemyright"); } } else { TimeCountdown -= Time.deltaTime; } }
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { player = GameObject.FindGameObjectWithTag("Player").transform; //这里通过anim clip所属animator获取 animator所挂载物体的刚体信息 en_parent_rb = animator.transform.parent.GetComponent <Rigidbody2D>(); //如果不在这里赋予enemy引用变量实例,虽然没有编译错误,下面会无法调用LookAtPlayer()方法 enemy_facing = animator.GetComponent <EnemyFacing>(); }
void Start() { xLength = 0f; yLength = 0f; enemyMoving = false; seePlayer = false; trackingPlayer = false; facing = EnemyFacing.DOWN; Physics2D.IgnoreCollision(p.GetComponent <Collider2D>(), GetComponent <Collider2D>()); }
public void EnemyFacePlayer() { CanSeePlayer(); if (seePlayer) { xLength = Mathf.Abs(p.transform.position.x - transform.position.x); yLength = Mathf.Abs(p.transform.position.y - transform.position.y); // possible values, 'enemyup', 'enemydown', 'enemyleft', 'enemyright', 'enemyinvis' if (yLength >= xLength) { if (p.transform.position.y > transform.position.y) { facing = EnemyFacing.UP; AnimateEnemyFace("enemyup"); } else { facing = EnemyFacing.DOWN; AnimateEnemyFace("enemydown"); } } else { if (p.transform.position.x > transform.position.x) { facing = EnemyFacing.RIGHT; AnimateEnemyFace("enemyright"); } else { facing = EnemyFacing.LEFT; AnimateEnemyFace("enemyleft"); } } } }
public bool CheckFacingPlayer() { float x = Mathf.Abs(p.transform.position.x - transform.position.x); float y = Mathf.Abs(p.transform.position.y - transform.position.y); if (y >= x) { if (p.transform.position.y > transform.position.y) { desired = EnemyFacing.UP; } else { desired = EnemyFacing.DOWN; } } else { if (p.transform.position.x > transform.position.x) { desired = EnemyFacing.RIGHT; } else { desired = EnemyFacing.LEFT; } } if (desired == facing) { return(true); } else { return(false); } }