Пример #1
0
    // Update is called once per frame
    void Update()
    {
        // left, right
        float horizontalInput = Input.GetAxisRaw("Horizontal");

        if (Input.GetKeyDown(KeyCode.Space) && touchedGround)
        {
            rigidbody.AddForce(Vector2.up * jumpSpeed, ForceMode2D.Impulse);
            jumped        = true;
            touchedGround = false;
            playerAnimation.SetTrigger("Jump");
        }
        rigidbody.AddForce(Vector2.right * horizontalInput * moveSpeed, ForceMode2D.Force);

        /*if (touchGroundToAllowJump && touchedGround || !touchGroundToAllowJump){
         *
         * }*/
        //moveDone.x = horizontalInput*moveSpeed*Time.deltaTime;
        if (horizontalInput != 0)
        {
            facingDirection = horizontalInput;
        }
        // left/right scaling
        transform.localScale = new Vector3(facingDirection, 1, 1);


        Vector3 aimPt = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        arm.UpdateArmDirection(aimPt, facingDirection < 0); // for negative, turn the aiming
        if (Input.GetKey(KeyCode.Mouse0) && fireTime < Time.time)
        {
            fireTime = Time.time + fireRate;
            if (sPCount > 0)
            {
                arm.SpecialAttack();
                sPCount--;
                sPCounter.text = "" + sPCount;
                ChangeSprite();
            }

            arm.Fire();
        }

        if (Time.time > 60)
        {
            GetComponent <HealthController>().Damage(999999);
        }
    }
Пример #2
0
 void ShootLight()
 {
     gun.armRoot.up = -((Vector2)player.position - (Vector2)transform.position);
     gun.Fire();
 }
    private void Shoot()
    {
        if (isLeftRetrieving || isRightRetrieving || !isGrounded || isStateFixed)
        {
            return;
        }

        // Charge
        if ((Input.GetKey(KeyCode.L) || Input.GetKey(KeyCode.F)) && arms != 0)
        {
            // Charging start.
            state = State.charge;
            // Play charge sound
            if (!isChargeSoundPlaying)
            {
                isChargeSoundPlaying = true;
                StartCoroutine(PlayChargeSound());
            }
            // Player can't move while charging.
            isMovable = false;
            // Increase power until limit;
            if (power < powerLimit)
            {
                power += powerIncrement;
            }

            for (int i = 0; i < 5; i++)
            {
                if (power / powerLimit >= 0.2f * (i + 1))
                {
                    if (lastDir == 1)
                    {
                        gauges[i].transform.localPosition = (new Vector2(-18.0f, 0.8f + 2.4f * i));
                    }
                    else if (lastDir == -1)
                    {
                        gauges[i].transform.localPosition = (new Vector2(18.0f, 0.8f + 2.4f * i));
                    }
                    gauges[i].SetActive(true);
                }
            }
        }
        else
        {
            gauges[0].SetActive(false);
            gauges[1].SetActive(false);
            gauges[2].SetActive(false);
            gauges[3].SetActive(false);
            gauges[4].SetActive(false);
        }

        // Fire
        if ((Input.GetKeyUp(KeyCode.L) || Input.GetKeyUp(KeyCode.F)) && arms != 0)
        {
            // Firing start.
            state = State.fire;
            // Wait for the fire animation to finish.
            Invoke("FinishFire", 0.3f);
            // Player's state is fixed while the animation is playing
            isStateFixed = true;
            // Call HandController class's function to actually fire
            if (arms == 2)
            {
                firstArm.Fire(power);
            }
            if (arms == 1)
            {
                if (enabledArms == 1)
                {
                    firstArm.Fire(power);
                }
                else
                {
                    secondArm.Fire(power);
                }
            }
            // Play Fire sound
            fireSound.source.Play();
            power = 0.0f;
        }
    }