コード例 #1
0
 void AutoAttack()
 {
     //target = GameObject.FindGameObjectWithTag("Player").transform;
     if (target != null)
     {
         PlayerState playerState = target.GetComponent <playerAnimation>().bigstate;
         if (playerState == PlayerState.Death)
         {
             target = null;
             state  = bossState.idle;
             return;
         }
         float distance = Vector3.Distance(target.position, transform.position);
         if (distance > maxDistance)              //停止自动攻击
         //target = null;
         {
             state = bossState.idle;
         }
         else if (distance <= minDistance)                //自动攻击
         {
             transform.LookAt(target);
             attack_timer += Time.deltaTime;
             animation_wolf.CrossFade(aniname_attack_now);
             if (aniname_attack_now == aniname_normalattack)
             {
                 if (attack_timer > time_normalattack)
                 {
                     //产生伤害
                     target.GetComponent <playerAttack>().TakeDamage(attack);
                     aniname_attack_now = animation_idle;
                 }
             }
             else if (aniname_attack_now == aniname_crazyattack)
             {
                 if (attack_timer > time_crazyattack)
                 {
                     //产生伤害
                     target.GetComponent <playerAttack>().TakeDamage(attack + 10);
                     aniname_attack_now = animation_idle;
                 }
             }
             if (attack_timer > (1f / attack_rate))
             {
                 RandomAttack();
                 attack_timer = 0;
             }
         }
         else                //朝着角色移动
         {
             transform.LookAt(target);
             //cc.SimpleMove(transform.forward * speed);
             transform.Translate(0, 0, 1 * speed * Time.deltaTime);
             animation_wolf.CrossFade(animation_walk);
         }
     }
     else
     {
         state = bossState.idle;
     }
 }
コード例 #2
0
 void Walk(direction moveInDirection)
 {
     if (moveInDirection == direction.right)
     {
         animator.SetBool("walkRight", true);
         animator.SetBool("walkLeft", false);
         if (transform.position.x <= 5.8)
         {
             transform.position += Vector3.right * speed * Time.deltaTime;
         }
         else
         {
             actualState = bossState.NextDirection;
         }
         actualDirection = direction.right;
     }
     else if (moveInDirection == direction.left)
     {
         animator.SetBool("walkRight", false);
         animator.SetBool("walkLeft", true);
         if (transform.position.x >= -3.4)
         {
             transform.position += Vector3.left * speed * Time.deltaTime;
         }
         else
         {
             actualState = bossState.NextDirection;
         }
         actualDirection = direction.left;
     }
     else
     {
     }
 }
コード例 #3
0
 // Update is called once per frame
 void Update()
 {
     if (target != null)
     {
         if (Vector3.Distance(transform.position, target.position) < maxDistance)
         {
             state = bossState.attack;
         }
     }
     if (state == bossState.death)
     {
         animation_wolf.CrossFade(animation_death);
     }
     else if (state == bossState.attack)
     {
         //StartCoroutine (turn_idle ());
         AutoAttack();
     }
     else
     {
         animation_wolf.CrossFade(animation_now);
         if (animation_now == animation_walk)
         {
             transform.Translate(0, 0, 1 * speed * Time.deltaTime);
         }
         timer += Time.deltaTime;
         if (timer >= time)
         {
             timer = 0;
             RandomState();
         }
     }
 }
コード例 #4
0
    public void TakeHit()
    {
        currentState = bossState.hurt;
        hurtCounter  = hurtTime;
        anim.SetTrigger("Hit");
        AudioManager.instance.PlaySFX(0);

        BossTankMine[] mines = FindObjectsOfType <BossTankMine>();
        if (mines.Length > 0)
        {
            foreach (BossTankMine foundMine in mines)
            {
                foundMine.Explode();
            }
        }

        health--;
        if (health <= 0)
        {
            isDefeated = true;
        }
        else
        {
            timeBetweenShoots /= shotSpeedUp;
            timeBetweenMines  /= mineSpeedUp;
        }
    }
コード例 #5
0
 private void EndMovement()
 {
     currentState = bossState.shooting;
     shotCounter  = 0f;
     anim.SetTrigger("StopMoving");
     hitBox.SetActive(true);
 }
コード例 #6
0
    private void activateing()
    {
        Debug.Log("height = " + gameObject.transform.position.y.ToString());
        if (gameObject.transform.position.y >= height)
        {
            if (vel > 0)
            {
                vel = vel - acc * Time.deltaTime;
                Vector3 pos = gameObject.transform.position;
                pos.y = gameObject.transform.position.y + vel * Time.deltaTime;
                gameObject.transform.position = pos;
            }
            else
            {
                myBossState = bossState.shielded;
            }
        }
        else
        {
            setShield(true);

            if (vel < speed)
            {
                vel = vel + (acc * Time.deltaTime);
            }
            Vector3 pos = gameObject.transform.position;
            pos.y = gameObject.transform.position.y + vel * Time.deltaTime;
            gameObject.transform.position = pos;
        }
    }
コード例 #7
0
    public void TakeDamage(int attack)      //受到伤害
    {
        if (state == bossState.death)
        {
            return;
        }
        target = GameObject.FindGameObjectWithTag("Player").transform;
        state  = bossState.attack;
        float value = 1f;

        if (value < miss_rate)          // Miss效果
        {
            AudioSource.PlayClipAtPoint(miss_sound, transform.position);
            showhurt("Miss");
            //hudtext.Add("Miss", Color.gray, 1);
        }
        else            //打中的效果
                        //hudtext.Add("-"+attack, Color.red, 1);
        {
            showhurt((0 - attack).ToString());
            this.hp -= attack;
            StartCoroutine(ShowBodyRed());
            if (hp <= 0)
            {
                target = null;
                state  = bossState.death;
                DestroySelf();
            }
        }
    }
コード例 #8
0
ファイル: Boss.cs プロジェクト: heshuai111/NightRaidRpg
    // Update is called once per frame
    void Update()
    {
        animation.CrossFade(animall_now);
        float distance = Vector3.Distance(target.position, transform.position); //计算玩家与野怪的距离

        if (distance <= maxDistance)                                            //判断玩家是否在野怪的攻击范围内
        {
            state = bossState.Attack;
        }
        if (state == bossState.Attack)
        {
            AutoAttack();                  //野怪执行攻击
        }
        else if (state == bossState.Death) //如果野怪的状态是死亡,则播放死亡动画
        {
            animation.CrossFade(animall_death);
        }
        else//野怪处于其他状态
        {
            animation.CrossFade(animall_now);//播放野怪当前动画
            if (animall_now == animall_walk)
            {
                cc.SimpleMove(transform.forward * speed);
            }
            timer += Time.deltaTime;//计时器
            if (timer >= time)
            {
                timer = 0;
                RandomState();//随机产生行走和静立状态
            }
        }
    }
コード例 #9
0
 private void takeDamage(float damage)
 {
     health -= damage;
     if (health <= 0)
     {
         myBossState = bossState.dead;
     }
 }
コード例 #10
0
 private void shielded()
 {
     setShield(true);
     if (Time.time > shieldTime)
     {
         setShield(false);
         myBossState = bossState.seeking;
     }
 }
コード例 #11
0
 // Use this for initialization
 void Start()
 {
     Player = GameObject.FindGameObjectWithTag("Player");
     //Level = GameObject.Find ("Level");
     myBossState = bossState.idel;
     Shots       = GameObject.FindGameObjectsWithTag("hardpoint");
     RangeMax    = Shots.Length;
     shield      = GameObject.Find("Shield");
     speed       = Player.GetComponent <PlayerMovement> ().speed *speedMulti;
 }
コード例 #12
0
ファイル: Boss.cs プロジェクト: heshuai111/NightRaidRpg
    private CharacterController cc; //角色控制器
    //public CharacterAttackSystem c;

    /* private void Awake()
     * {
     *   //normal = render.material.color;
     * }*/

    // Start is called before the first frame update
    void Start()
    {
        state              = bossState.Idle;                     //初始化初始状态
        animall_now        = animall_idle;                       //初始化初始动画
        aniname_attack_now = aniname_normalattack;               //初始化攻击动画
        cc        = this.GetComponent <CharacterController>();
        player    = GameObject.FindGameObjectWithTag("monster"); //获取玩家对象
        render    = GetComponent <Renderer>();
        target    = player.transform;                            //获取玩家的位置
        animation = GetComponent <Animation>();
    }
コード例 #13
0
ファイル: SkeltonBossAI.cs プロジェクト: spriggan4/MyProject
    void Update()
    {
        if ((!target) || (isDead))
        {
            return;
        }

        myPos     = this.transform.position;
        targetPos = target.position;
        distance  = Vector3.Distance(myPos, targetPos);


        if (moveableRadius > distance)
        {
            LookAtPlayer();
            if (state == bossState.none)
            {
                attackDelay -= Time.deltaTime;

                if (attackDelay < 0f)
                {
                    state = bossState.longAtk;
                }
            }

            // 패턴 2, 원거리 공격
            else if (state == bossState.longAtk)
            {
                bossAttack.LongDistanceAttack();

                attackDelay = 4f;

                state = bossState.none;

                ++attackCount;

                if (attackCount == 5)
                {
                    state = bossState.waiting;
                }
            }

            else if (state == bossState.waiting)
            {
                waitingDelay -= Time.deltaTime;
                if (waitingDelay < 0)
                {
                    state        = bossState.none;
                    waitingDelay = 4f;
                }
            }
        }
    }
コード例 #14
0
 private void seeking()
 {
     if (Vector3.Distance(Player.transform.position, gameObject.transform.position) > seekRange)
     {
         Vector3 direction = (Player.transform.position - gameObject.transform.position);
         direction.Normalize();
         gameObject.transform.position = gameObject.transform.position + (direction * speed * Time.deltaTime);
     }
     else
     {
         duration    = Time.time + Random.Range(7.0f, 15.0f);
         shotState   = GetRandomEnum <shotMode>();
         myBossState = bossState.shooting;
     }
 }
コード例 #15
0
 void Teletransport()
 {
     if (!(waitTransport > 0))
     {
         float posX = Random.Range(-3.4f, 5.8f);
         float posY = Random.Range(-2.1f, 1.9f);
         transform.position = new Vector2(posX, posY);
         PuffSmoke();
         actualState   = bossState.Walk;
         waitTransport = 100;
     }
     else
     {
         transform.position = new Vector2(-50f, -50f);
     }
     waitTransport--;
 }
コード例 #16
0
 void Fire()
 {
     if (numFire <= randomFire)
     {
         GameObject fireEnemy = Instantiate(fire, new Vector3(transform.position.x, transform.position.y + 1, -13f), Quaternion.identity) as GameObject;
         numFire++;
     }
     else
     {
         if (!(waitFire > 0))
         {
             actualState = bossState.Walk;
             waitFire    = 50;
             RandomFire();
             actualDirection = direction.left;
         }
         waitFire--;
     }
 }
コード例 #17
0
    // Update is called once per frame
    void Update()
    {
        switch (actualState)
        {
        case bossState.NextDirection:

            NextDirection();
            break;

        case bossState.Walk:

            Walk((direction)actualDirection);
            break;

        case bossState.Teletransport:
            Teletransport();
            break;

        default:
            break;
        }
        if (changeDirection)
        {
            actualState = bossState.NextDirection;
        }
        else
        {
        }
        if (!(waitTime > 0))
        {
            AudioSource.PlayClipAtPoint(clip, transform.position, 5000f);
            PuffSmoke();
            actualState = bossState.Teletransport;
            waitTime    = 300;
        }
        waitTime--;
        if (health <= 0)
        {
            GameObject.Find("Door").GetComponent <Door>().isOpen = true;
            Destroy(gameObject);
        }
    }
コード例 #18
0
    // Update is called once per frame
    void Update()
    {
        switch (actualState)
        {
        case bossState.NextDirection:

            NextDirection();
            break;

        case bossState.Walk:

            Walk((direction)actualDirection);
            break;

        case bossState.Fire:
            Fire();
            break;

        default:
            break;
        }
        if (changeDirection)
        {
            actualState = bossState.NextDirection;
        }
        else
        {
        }
        if (!(waitTime > 0))
        {
            actualDirection = direction.idle;
            actualState     = bossState.Walk;
            waitTime        = Random.Range(150, 300);
            AudioSource.PlayClipAtPoint(clip, transform.position, 1f);
        }
        waitTime--;
        if (health <= 0)
        {
            GameObject.Find("Door").GetComponent <Door>().isOpen = true;
            Destroy(gameObject);
        }
    }
コード例 #19
0
    private void ShootPlayer()
    {
        if (Time.time > duration)
        {
            myBossState = bossState.wave;
        }
        else
        {
            switch (shotState)
            {
            case shotMode.laserFire:
                randomFire();
                break;

//		case shotMode.maxLaserFire:
//			FireAll();
//			break;
            case shotMode.rocketFire:
                randomRocket();
                break;

//		case shotMode.maxRocketFire:
//			FireAllRocket();
//			break;
            case shotMode.seekerFire:
                randomSeeker();
                break;
//		case shotMode.maxSeekerFire:
//			FireAllSeeker();
//			break;
//		case shotMode.WW3:
//			FireAllRocket();
//			FireAllSeeker();
//			FireAll();
//			randomRocket();
//			randomSeeker();
//			randomFire();
//			break;
            }
        }
    }
コード例 #20
0
 void NextDirection()
 {
     randomDirection = Random.Range(0, 1);
     if (randomDirection == (int)actualDirection)
     {
         if (randomDirection >= 1)
         {
             randomDirection--;
         }
         else if (randomDirection <= 0)
         {
             randomDirection++;
         }
         else
         {
             randomDirection++;
         }
     }
     actualState     = bossState.Walk;
     actualDirection = (direction)randomDirection;
     changeDirection = false;
 }
コード例 #21
0
ファイル: Boss.cs プロジェクト: heshuai111/NightRaidRpg
    public void TakeDamage(int attack)
    {
        if (state == bossState.Death)
        {
            return;
        }
        float value = Random.Range(0f, 1f);

        if (value < miss_rate)//Miss效果
        {
            //AudioSource.PlayClipAtPoint(miss_sound, transform.position);
        }
        else
        {
            this.hp -= attack;
            Slider_c6.instance.SetValue(hp);
            //StartCoroutine(ShowBodyRed());
            if (hp <= 0)
            {
                state = bossState.Death;
                Destroy(this.gameObject, 2);
            }
        }
    }
コード例 #22
0
    // Update is called once per frame
    void Update()
    {
        switch (actualState)
        {
        case bossState.NextDirection:

            NextDirection();
            break;

        case bossState.Walk:

            Walk((direction)actualDirection);
            break;

        default:
            break;
        }
        if (changeDirection)
        {
            actualState = bossState.NextDirection;
        }
        else
        {
        }
        if (!(waitTime > 0))
        {
            changeDirection = true;
            waitTime        = 100;
        }
        waitTime--;
        if (health <= 0)
        {
            GameObject.Find("Door").GetComponent <Door>().isOpen = true;
            Destroy(gameObject);
        }
    }
コード例 #23
0
ファイル: BossBehaviour.cs プロジェクト: yohash/Gradius
    public override void Move()
    {
        getPlayerLoc();         // find the players location the set the boss's
                                // upper and lower roam limits

        //      Big ugly if-else chain that  uses state space variables to
        // have the ship scan up and down vertically (y) from the player location.
        //      Fire() timing is independant.
        //      If the player hides in a corner, the ship is supposed to freeze at
        // top or bottom ~1sec then fire.

        if (bs == bossState.entering && this.transform.position.x >= 7f)
        {   // this controls the boss entering, and starts his fight
            fireTimer = Time.time;
            firing    = true;
            this.transform.position += Time.deltaTime * new Vector3(-speed, 0f, 0f);
        }
        else if (bs == bossState.entering && this.transform.position.x <= 7f)
        {
            // initiate lasers if custom level
            if (customLevel)
            {
                GetComponentInChildren <laserPointerFire>().initiateFire();
            }
            // initiate boss fight
            bs = bossState.fightingUP;
        }
        else if (bs == bossState.fightingUP && this.transform.position.y < bossTopLim)
        {   // move boss upwards if he hasnt reached his limit
            this.transform.position += Time.deltaTime * new Vector3(0f, fightSpeed, 0f);
        }
        else if (bs == bossState.fightingUP && this.transform.position.y >= bossTopLim)
        {   // boss reached his upper limit
            this.transform.position = new Vector3(this.transform.position.x, bossTopLim, 0f);

            // trigger a pause if the player is hiding in upper corner
            if (this.transform.position.y + 0.5f >= topLim && playerPos.y >= 7f)
            {
                pauseTimer = Time.time;
                bs         = bossState.pausing;
            }
            else
            {   // player isnt hiding... start going downward
                bs = bossState.fightingDOWN;
            }
        }
        else if (bs == bossState.fightingDOWN && this.transform.position.y > bossBotLim)
        {   // move boss downward if he hastn reached his limit
            this.transform.position -= Time.deltaTime * new Vector3(0f, fightSpeed, 0f);
        }
        else if (bs == bossState.fightingDOWN && this.transform.position.y <= bossBotLim)
        {   // boss reached his lower limit
            this.transform.position = new Vector3(this.transform.position.x, bossBotLim, 0f);

            // trigger a pause if the player is hiding in bottom corner
            if (this.transform.position.y - 0.5f <= botLim && playerPos.y <= -4f)
            {
                pauseTimer = Time.time;
                bs         = bossState.pausing;
            }
            else
            {   // player isnt hiding... move on up
                bs = bossState.fightingUP;
            }
        }
        else if (bs == bossState.pausing && (Time.time - pauseTimer) > 0.7f)
        {
            // boss has paused 1 sec
            // player is hiding in a corner - pause then shoot at them

            Fire();
            fireTimer = Time.time;      // reset timer to prevent boss ship from "double fire"

            if (this.transform.position.y > 0)
            {   // if at the top, fight on down
                bs = bossState.fightingDOWN;
            }
            else
            {   // if at the bottom, fight on up
                bs = bossState.fightingUP;
            }
        }
    }
コード例 #24
0
 private void wave()
 {
     shieldTime  = Time.time + shieldDuration;
     myBossState = bossState.shielded;
 }
コード例 #25
0
    // Update is called once per frame
    void Update()
    {
        switch (currentState)
        {
        case bossState.shooting:
            shotCounter -= Time.deltaTime;
            if (shotCounter <= 0)
            {
                shotCounter = timeBetweenShoots;
                var newBullet = Instantiate(bullet, firePoint.position, firePoint.rotation);
                newBullet.transform.localScale = theBoss.localScale;
            }

            break;

        case bossState.hurt:
            if (hurtCounter > 0)
            {
                hurtCounter -= Time.deltaTime;
                if (hurtCounter <= 0)
                {
                    currentState = bossState.moving;

                    mineCounter = 0;

                    if (isDefeated)
                    {
                        theBoss.gameObject.SetActive(false);
                        Instantiate(explosion, theBoss.position, theBoss.rotation);
                        winPlatform.SetActive(true);
                        AudioManager.instance.StopBossMusic();
                        currentState = bossState.ended;
                    }
                }
            }
            break;

        case bossState.moving:
            if (moveRight)
            {
                theBoss.position += new Vector3(moveSpeed * Time.deltaTime, 0f, 0f);

                if (theBoss.position.x > rightPoint.position.x)
                {
                    theBoss.localScale = new Vector3(1f, 1f, 1f);
                    moveRight          = false;

                    EndMovement();
                }
            }
            else
            {
                theBoss.position -= new Vector3(moveSpeed * Time.deltaTime, 0f, 0f);

                if (theBoss.position.x < leftPoint.position.x)
                {
                    theBoss.localScale = new Vector3(-1f, 1f, 1f);
                    moveRight          = true;

                    EndMovement();
                }
            }

            mineCounter -= Time.deltaTime;
            if (mineCounter <= 0)
            {
                mineCounter = timeBetweenMines;
                Instantiate(mine, minePoint.position, minePoint.rotation);
            }

            break;
        }

#if UNITY_EDITOR
        if (Input.GetKeyDown(KeyCode.H))
        {
            TakeHit();
        }
#endif
    }
コード例 #26
0
 // Start is called before the first frame update
 void Start()
 {
     currentState = bossState.shooting;
 }
コード例 #27
0
 public void Activate()
 {
     myBossState = bossState.activating;
 }
コード例 #28
0
 void Walk(direction moveInDirection)
 {
     if (moveInDirection == direction.right)
     {
         animator.SetBool("walkRight", true);
         animator.SetBool("walkLeft", false);
         animator.SetBool("walkUp", false);
         animator.SetBool("walkDown", false);
         if (transform.position.x <= 5.8)
         {
             transform.position += Vector3.right * speed * Time.deltaTime;
         }
         else
         {
             actualState = bossState.NextDirection;
         }
         actualDirection = direction.right;
     }
     else if (moveInDirection == direction.left)
     {
         animator.SetBool("walkRight", false);
         animator.SetBool("walkLeft", true);
         animator.SetBool("walkUp", false);
         animator.SetBool("walkDown", false);
         if (transform.position.x >= -3.4)
         {
             transform.position += Vector3.left * speed * Time.deltaTime;
         }
         else
         {
             actualState = bossState.NextDirection;
         }
         actualDirection = direction.left;
     }
     else if (moveInDirection == direction.up)
     {
         animator.SetBool("walkUp", true);
         animator.SetBool("walkRight", false);
         animator.SetBool("walkLeft", false);
         animator.SetBool("walkDown", false);
         if (transform.position.y <= 1.9)
         {
             transform.position += Vector3.up * speed * Time.deltaTime;
         }
         else
         {
             actualState = bossState.NextDirection;
         }
         actualDirection = direction.up;
     }
     else if (moveInDirection == direction.down)
     {
         //transform.rotation = Quaternion.Slerp(startRotation, desiredAngle, .5f);
         animator.SetBool("walkDown", true);
         animator.SetBool("walkRight", false);
         animator.SetBool("walkLeft", false);
         animator.SetBool("walkUp", false);
         if (transform.position.y >= -2.1)
         {
             transform.position += Vector3.down * speed * Time.deltaTime;
         }
         else
         {
             actualState = bossState.NextDirection;
         }
         actualDirection = direction.down;
     }
     else
     {
     }
 }