コード例 #1
0
ファイル: Shooting.cs プロジェクト: pturner42/VGDesign
    // Update is called once per frame
    void Update()
    {
        timer += Time.deltaTime;
        if (shooting)
        {
            if (timer >= weapon.fireRate)
            {
                if (Time.timeScale != 0 && weapon.currentAmmo > 0)
                {
                    if (original)
                    {
                        weapon.currentAmmo--;
                    }
                    Shoot();
                }
                else
                {
                    timer = 0f;
                    emptyClip.Play();
                }
            }
        }
        else
        {
            timer = -3 * Time.deltaTime;
        }

        if (cooldown < Time.deltaTime)
        {
            gunLine.enabled = false;
        }
        else
        {
            cooldown -= Time.deltaTime;
        }

        if (original && disp != null)
        {
            disp.text = weapon.currentAmmo + "/" + weapon.maxAmmo;
        }
        //debug stuff
        if (original && (Input.GetKeyUp("r") || (ControlInputWrapper.GetButtonUp(ControlInputWrapper.Buttons.X))))
        {
            if (clipAmount > 0 && clips.Length != 0)
            {
                weapon.currentAmmo = weapon.maxAmmo;
                clipAmount--;
                clips[clipAmount].enabled = false;
            }
        }         /*else if (Input.GetKeyDown ("x")) {
                   *    ItemLibrary.createRandomItem(this.gameObject.transform.position);
                   * } */
//		if (Input.GetKeyUp ("m"))
//			addClip ();
//			if(timer >= timeBetweenBullets * effectsDisplayTime)
//			{
//				DisableEffects ();
//			}
    }
コード例 #2
0
    void handleMenuInput()
    {
        float h = Input.GetAxisRaw("Vertical");

        if (hostCode.enabled)
        {
            h = 0;
        }
        float yaxis         = ControlInputWrapper.GetAxis(ControlInputWrapper.Axis.LeftStickY);
        int   size          = menu.Length;
        int   t             = currentSelection;
        int   nextSelection = t;

        if (h != 0 && canMove)
        {
            canMove = false;
            if (h < 0)
            {
                nextSelection = (currentSelection + 1);
                if (nextSelection > size - 1)
                {
                    nextSelection = 0;
                }
            }
            else if (h > 0)
            {
                nextSelection = (currentSelection - 1);
                if (nextSelection < 0)
                {
                    nextSelection = size - 1;
                }
            }
        }
        else if (h == 0)
        {
            canMove = true;
        }

        if (t != nextSelection)
        {
            oldSelection = t;
            hoverOption(nextSelection);
        }

        //handles selections
        if (Input.GetKeyUp("space") || Input.GetKeyUp("return") || ControlInputWrapper.GetButton(ControlInputWrapper.Buttons.RightBumper))
        {
            if (canSelect)
            {
                handleSelection(menu[currentSelection].name);
                canSelect = false;
            }
        }
        else
        {
            canSelect = true;
        }
    }
コード例 #3
0
    public void Turning()
    {
        // Isometric turning
        if (isPlayer && !move.GetDead())
        {
            Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);

            RaycastHit floorHit;

            if (Input.GetJoystickNames().Length == 0)
            {
                if (Physics.Raycast(camRay, out floorHit, camRayLength, floorMask))
                {
                    Vector3 playerToMouse = floorHit.point - transform.position;
                    playerToMouse.y = 0f;

                    transform.rotation = Quaternion.LookRotation(playerToMouse);
                    //floorHit.transform.position = new Vector3(0, transform.position.y + 1f, 0);
                }
            }
            // Rotation

            float xaxis = ControlInputWrapper.GetAxis(ControlInputWrapper.Axis.RightStickX);
            float yaxis = ControlInputWrapper.GetAxis(ControlInputWrapper.Axis.RightStickY);
            if (Mathf.Abs(xaxis) > 0.1f || Mathf.Abs(yaxis) > 0.1f)
            {
                Vector3 aiming = new Vector3(xaxis, 0, yaxis);
                setRotation(Quaternion.LookRotation(aiming).eulerAngles.y);
                move.setRotSpeed(15f);
            }

            turnTime += Time.deltaTime;
            if (transform.rotation.y != oldRotation && turnTime > 20 * Time.deltaTime)
            {
                oldRotation = transform.rotation.y;
                turnUpdate  = true;
            }
        }
        // Third person turning

        /* else {
         *      float turnSpeed = Time.deltaTime * 100;
         *      if (Input.GetKey ("j")) {
         *              transform.Rotate (0, -turnSpeed, 0);
         *      } else if (Input.GetKey ("l")) {
         *              transform.Rotate (0, turnSpeed, 0);
         *      }
         * } */
    }
コード例 #4
0
ファイル: PlayerController.cs プロジェクト: JELGT2011/CS-4455
    void FixedUpdate()
    {
        float X = ControlInputWrapper.GetAxis(ControlInputWrapper.Axis.LeftStickX);
        float Y = ControlInputWrapper.GetAxis(ControlInputWrapper.Axis.LeftStickY);
        //float X = 0.5f;
        //float Y = 0.5f;
        float Speed = Mathf.Min(Mathf.Sqrt((X * X) + (Y * Y)), 1f);
        float Angle = Mathf.Rad2Deg * Mathf.Atan(X / Y);

        if (float.IsNaN(Angle))
        {
            Angle = 0f;
        }

        if (Y < 0f)
        {
            Angle += 180f;
        }


        _controllerGUI.text = "Y: " + X + "\n"
                              + "X: " + Y + "\n"
                              + "Speed: " + Speed + "\n"
                              + "Angle: " + Angle
        ;

        _animator.SetFloat("speed", Speed);

        transform.rotation = Quaternion.Euler(0f, Angle, 0f);

        if (ControlInputWrapper.GetButtonDown(ControlInputWrapper.Buttons.A))
        {
            _animator.SetTrigger("jump");
        }
        else if (ControlInputWrapper.GetButtonDown(ControlInputWrapper.Buttons.X))
        {
            _animator.SetTrigger("left_attack");
        }
        else if (ControlInputWrapper.GetButtonDown(ControlInputWrapper.Buttons.B))
        {
            _animator.SetTrigger("right_attack");
        }
        else if (ControlInputWrapper.GetButtonDown(ControlInputWrapper.Buttons.Y))
        {
            _animator.SetTrigger("center_combo");
        }
    }
コード例 #5
0
    void Update()
    {
        if (ControlInputWrapper.GetButton(ControlInputWrapper.Buttons.A))
        {
            Debug.Log("A");
        }
        if (isPlayer)
        {
            h = Input.GetAxisRaw("Horizontal");
            v = Input.GetAxisRaw("Vertical");
            float xaxis = ControlInputWrapper.GetAxis(ControlInputWrapper.Axis.LeftStickX);
            float yaxis = ControlInputWrapper.GetAxis(ControlInputWrapper.Axis.LeftStickY);
            if (h == 0 && v == 0)
            {
                if (Mathf.Abs(xaxis) > 0.5f)
                {
                    h = Mathf.Max(Mathf.Min(xaxis, 1f), -1f);
                }
                else
                {
                    h = 0;
                }
                if (Mathf.Abs(yaxis) > 0.5f)
                {
                    v = -Mathf.Max(Mathf.Min(yaxis, 1f), -1f);
                }
                else
                {
                    v = 0;
                }
            }

            if (Input.GetKey("space") || ControlInputWrapper.GetButton(ControlInputWrapper.Buttons.RightBumper))
            {
                shooting = true;
            }
            else
            {
                shooting = false;
            }

            if (move.GetDead())
            {
                h        = 0;
                v        = 0;
                shooting = false;
            }

            if ((h != oldH || v != oldV) && moveCountdown < 1)
            {
                oldH          = h;
                oldV          = v;
                needsUpdate   = true;
                moveCountdown = 4;
            }
            else
            {
                moveCountdown -= 1;
            }

            if (oldShooting != shooting)
            {
                needsUpdate = true;
                oldShooting = shooting;
            }

            if (Input.GetKey("q") || (ControlInputWrapper.GetButton(ControlInputWrapper.Buttons.Y)))
            {
                reviveBtn = true;
            }
            else
            {
                reviveBtn = false;
            }
        }

        shooter.setShooting(shooting);

        //this should be somewhere else

        /*CapsuleCollider cc = GetComponent<CapsuleCollider> ();
         * if (shooting) {
         *      h = 0;
         *      v = 0;
         *      cc.height = ccHeight * 0.8f;
         * } else {
         *      cc.height = ccHeight;
         * }*/

        move.Move(h, v);
        Turning();
        movement = move.getMove();

        Vector2 spdir = DetermineDir(h, v);

        move.backwards = spdir.x < 0;
        if (spdir.x == 0)
        {
            spdir.x = 0.05f;
        }
        if (!move.GetDead())
        {
            anim.SetFloat("SpeedAmnt", (spdir.x));
            anim.SetFloat("Direction", spdir.y, .25f, Time.deltaTime);
            anim.SetBool("Shooting", shooting);
        }
    }