Пример #1
0
        // Fixed update is called in sync with physics
        private void FixedUpdate()
        {
            // read inputs
            //float h = (m_inputManager.GetActive()) ? m_inputManager.GetAxis(Axis.Horizontal) : CrossPlatformInputManager.GetAxis("Horizontal");
            //float v = (m_inputManager.GetActive()) ? m_inputManager.GetAxis(Axis.Verticle) : CrossPlatformInputManager.GetAxis("Vertical");
            if (!m_player.isStunned)
            {
                float h = (m_inputManager.GetActive()) ? m_inputManager.GetAxis(Axis.Horizontal) :
                          (Input.GetKey(KeyCode.A)) ? -1 :
                          (Input.GetKey(KeyCode.D)) ? 1 :
                          0;
                float v = (m_inputManager.GetActive()) ? m_inputManager.GetAxis(Axis.Verticle) :
                          (Input.GetKey(KeyCode.W)) ? 1 :
                          (Input.GetKey(KeyCode.S)) ? -1 :
                          0;

                bool crouch = (m_inputManager.GetActive()) ? m_inputManager.GetButtonDown(Button.Crouch) : Input.GetKey(KeyCode.C);

                // calculate move direction to pass to character
                if (m_Cam != null)
                {
                    // calculate camera relative direction to move:
                    m_CamForward = Vector3.Scale(m_Cam.forward, new Vector3(1, 0, 1)).normalized;
                    m_Move       = v * m_CamForward + h * m_Cam.right;
                }
                else
                {
                    // we use world-relative directions in the case of no main camera
                    m_Move = v * Vector3.forward + h * Vector3.right;
                }
#if !MOBILE_INPUT
                // walk speed multiplier
                if (Input.GetKey(KeyCode.LeftShift))
                {
                    m_Move *= 0.5f;
                }
#endif

                // pass all parameters to the character control script
                m_Character.Move(m_Move, crouch, m_Jump);
                m_Jump = false;
            }
        }
Пример #2
0
    void ThrowObject()
    {
        if (collectibleList.Count > 0)
        {
            int lastIndex = collectibleList.Count - 1;

            Vector3 startingPosition;
            Vector3 force;
            collectibleList[lastIndex].rb.velocity = new Vector3(0, 0, 0);
            startingPosition = gameObject.transform.position + gameObject.transform.forward * 0.7f;

            startingPosition.y += 1f;
            collectibleList[lastIndex].transform.position = startingPosition;
            collectibleList[lastIndex].gameObject.SetActive(true);
            if (inputManager.GetActive())
            {
                Vector3 aimDirection = new Vector3(inputManager.GetAxis(Axis.RHorizontal), 0, inputManager.GetAxis(Axis.RVerticle));
                force = aimDirection.normalized;
            }
            else
            {
                force = gameObject.transform.forward;
            }

            force = force.normalized * throwSpeed;


            collectibleList[lastIndex].rb.AddForce(force);
            collectibleList[lastIndex].gameObject.tag = "Projectile";
            if (collectibleList[lastIndex].damage == 0)
            {
                collectibleList[lastIndex].damage = damage;
            }

            Physics.IgnoreCollision(collectibleList[lastIndex].gameObject.GetComponent <Collider>(), GetComponent <Collider>());
            collectibleList.RemoveAt(lastIndex);
        }
    }