コード例 #1
0
 // Use this for initialization
 public void Start()
 {
     nadeCooldown = 0f;
     nadeCount    = maxNadeCount;
     anim         = GetComponent <Animator>();
     bullet       = GetComponent <BulletShotFromBond> ();
     bondFly      = GetComponent <BondFlying> ();
 }
コード例 #2
0
    void Update()
    {
        nadeThrow = GetComponent <NadeThrowing> ();
        bondFly   = GetComponent <BondFlying> ();
        var currentState = anim.GetCurrentAnimatorStateInfo(0);

        if (shootCooldown > 0)
        {
            shootCooldown -= Time.deltaTime;
        }
        //стрельба
        if (Input.GetKeyDown(KeyCode.Mouse0) && bond.bondHp > 0)
        {
            nowIsShoot = true;
            anim.SetBool("IsShoot", true);
        }
        if (Input.GetKeyUp(KeyCode.Mouse0) || bulletsCount <= 0)
        {
            anim.SetBool("IsShoot", false);
            nowIsShoot = false;
        }

        if (nowIsShoot && bulletsCount > 0)
        {
            Attack();
        }
        //перезарядка
        if (bond.bondHp > 0 && !nowIsShoot && !nadeThrow.NowIsThrowing && !bondFly.isFlying && Input.GetKeyDown(KeyCode.R) && bulletsCount < maxBulletsCount && AllBulletsCount > 0 && bond.grounded && bond.isShooting == false)
        {
            anim.SetTrigger("IsReload");
            if (AllBulletsCount < 10)
            {
                bulletsCount = AllBulletsCount;
            }
            else
            {
                bulletsCount = maxBulletsCount;
            }
        }
        if (currentState.IsName("reload"))
        {
            nowIsReload = true;
        }
        else
        {
            nowIsReload = false;
        }
    }
コード例 #3
0
 public void Attack()
 {
     nadeThrow = GetComponent <NadeThrowing> ();
     bondFly   = GetComponent <BondFlying> ();
     if (bond.bondHp > 0 && CanShoot && !nowIsReload && !nadeThrow.NowIsThrowing && !bondFly.isFlying)
     {
         audio.PlayOneShot(myaudio);
         bulletsChange();
         shootCooldown = shootRate;
         var shootTransform = Instantiate(shootPrefab) as Transform;
         if (bond.facingRight)
         {
             shootTransform.position = new Vector2(transform.position.x + 0.3f, transform.position.y + 0.1f);
         }
         else
         {
             shootTransform.position = new Vector2(transform.position.x - 0.3f, transform.position.y + 0.1f);
         }
     }
 }
コード例 #4
0
    void Update()
    {
        if (!loadingLevel)
        {
            BondFlying bondFly = GetComponent <BondFlying> ();
            grounded    = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround);
            onEnemyHead = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsEnemyHead);
            move        = Input.GetAxis("Horizontal");
            anim.SetFloat("Speed", Mathf.Abs(move));
            anim.SetFloat("vSpeed", rigidbody2D.velocity.y);
            BulletShotFromBond shoot     = GetComponent <BulletShotFromBond> ();
            NadeThrowing       nadeThrow = GetComponent <NadeThrowing> ();
            bondHealthBar = (float)bondHp / bondHpMax;

            if (facingRight)
            {
                bullet.orientation = 1f;
                nade.orientation   = 1f;
            }
            else
            {
                bullet.orientation = -1f;
                nade.orientation   = -1f;
            }


            if (bondHp > 0)
            {
                anim.SetBool("Ground", grounded);
                groundRadius = 0.2f;
                if (!nadeThrow.NowIsThrowing)
                {
                    rigidbody2D.velocity = new Vector2(move * maxSpeed, rigidbody2D.velocity.y);
                    if (!bondFly.isFlying && !shoot.nowIsReload && grounded && Input.GetKeyDown(KeyCode.Space))
                    {
                        anim.SetBool("Ground", false);
                        rigidbody2D.AddForce(new Vector2(0f, jumpForce));
                    }
                    if (move > 0 && !facingRight)
                    {
                        Flip();
                    }
                    else if (move < 0 && facingRight)
                    {
                        Flip();
                    }
                }
            }
            else
            {
                anim.SetBool("Dead", true);
                groundRadius         = 0.1f;
                rigidbody2D.velocity = new Vector2(0, rigidbody2D.velocity.y);
                deadwindow           = true;
                if (onLift)
                {
                    rigidbody2D.isKinematic = false;
                }
                else
                if (grounded)
                {
                    rigidbody2D.isKinematic = true;
                }
            }

            if (onEnemyHead)
            {
                anim.SetBool("Ground", onEnemyHead);
            }

            if (Input.GetKey(KeyCode.F3) && bondHp > 0)
            {
                bondHpMax = int.MaxValue;
                bondHp    = int.MaxValue;
            }
        }
    }