Exemplo n.º 1
0
    private void HandleActionPress()
    {
        if (!Input.GetButtonDown(_commandMap[Commands.Fire]))
        {
            return;
        }

        if (!_pillow)
        {
            // ReSharper disable once Unity.PreferNonAllocApi
            var results = Physics.OverlapSphere(transform.position, 1, throwable);
            if (!(results?.Length > 0))
            {
                return;
            }
            foreach (var result in results)
            {
                var temPillow = result.transform.GetComponent <Pillow>();
                if (temPillow.heldBy != null)
                {
                    continue;
                }
                _pillow = temPillow;
                _pillow.AttachToPlayer(handTransform, this);
                animator.SetBool("RunGrab", true);
                return;
            }
        }
        else
        {
            _pillow.Throw(playerNumber == 1 ? transform.forward : transform.forward * -1);
            _pillow = null;
            animator.SetBool("RunGrab", false);
            _audioSource.PlayOneShot(throwClips[UnityEngine.Random.Range(0, throwClips.Length)]);
        }
    }
Exemplo n.º 2
0
    public void ThrowMecanimPillow()
    {
        if (pillow == null)
        {
            return;
        }

        Transform target = _autoTarget.GetTarget(transform.forward);

        Vector3 direction;

        if (target != null)
        {
            direction = target.transform.position - pillow.transform.position;
        }
        else
        {
            direction = transform.forward;
        }

        direction = direction.normalized;

        pillow.gameObject.SetActive(true);
        pillow.transform.localPosition    = new Vector3(0.109f, -0.407f, 0.389f);
        pillow.transform.localEulerAngles = new Vector3(0f, 204.46f, 310.0002f);

        AnimationPillow.SetActive(false);

        pillow.Throw(direction * ThrowForce);

        pillow.IsOwned = false;

        target = null;

        pillow = null;
    }
Exemplo n.º 3
0
    void FixedUpdate()
    {
        if (!isPushedBack)
        {
            // Picking up pillows
            if (Input.GetAxis("Pick" + ControllerId) == 0)
            {
                isSubmitButtonUp = true;
            }
            else if (isSubmitButtonUp)
            {
                isSubmitButtonUp = false;

                if (NumPillowsHeld >= 2) // exceed the number that one player can hold
                {
                    Drop();
                }
                else
                {
                    PickUp();
                }
            }

            //Attack
            if (Input.GetAxis("Attack" + ControllerId) == 0)
            {
                isAttackButtonUp = true;
            }
            else if (isAttackButtonUp)
            {
                isAttackButtonUp = false;

                top.SetInteger("CurrentState", 4);
                StartCoroutine(AttackFinish());

                if (numPillowHold == 0)
                {
                    // that is a punch
                    SlotLA.GetComponent <SphereCollider>().enabled = true;
                }
                else
                {
                    // a Pillow Sweep
                    if (numPillowHold == 1)
                    {
                        AudioManager.Instance.PlaySoundEffect("PillowNearFight", false);
                        var temp = Ammo.Peek();
                        temp.Attack();
                    }
                }
            }

            // Tossing pillows
            if (Input.GetAxis("Toss" + ControllerId) == 0)
            {
                if (!isCancelButtonUp && NumPillowsHeld > 0)
                {
                    Pillow pillow = Ammo.Dequeue();
                    pillow.Throw(model.transform.forward, model.transform.up, (emPower - 0.08f + 1) * powerThrowForward, (emPower + 1) * powerThrowUpper);
                    pillow.transform.parent = transform.parent;

                    top.SetInteger("CurrentState", 3);
                    StartCoroutine(ThrowFinish());
                    emPower = 0;
                    NumPillowsHeld--;
                }

                isCancelButtonUp = true;
            }
            else if (isCancelButtonUp)
            {
                isCancelButtonUp = false;

                if (NumPillowsHeld > 0)
                {
                    Pillow pillow = Ammo.Peek();
                    pillow.ReadyToGo();

                    if (numPillowHold == 1)
                    {
                        pillow.transform.parent        = SlotRA;
                        pillow.transform.localPosition = Vector3.zero;
                        pillow.transform.localRotation = Quaternion.identity;
                    }

                    emPower = minThrowPower;
                    top.SetInteger("CurrentState", 1);
                }
            }

            if (!isCancelButtonUp && emPower > 0)
            {
                emPower = Mathf.Min(emPower + powerToAddEachFrame * Time.fixedDeltaTime, maxThrowPower);
            }

            if (controller.isGrounded)
            {
                // We are grounded, so recalculate
                // move direction directly from axes

                moveDirection = new Vector3(Input.GetAxis("Horizontal" + ControllerId), 0.0f, Input.GetAxis("Vertical" + ControllerId));
                if (moveDirection.sqrMagnitude > 0.2f)
                {
                    //moveDirection = Quaternion.Euler(0, -45, 0) * transform.TransformDirection(moveDirection);
                    moveDirection = moveDirection.normalized;

                    top.SetFloat("Speed", speed);
                    buttom.SetFloat("Speed", speed);
                    model.transform.forward = moveDirection;
                }
                else
                {
                    moveDirection = Vector3.zero;

                    top.SetFloat("Speed", 0);
                    buttom.SetFloat("Speed", 0);
                }

                //if (Input.GetButton("Jump"))
                //{
                //    moveDirection.y = jumpSpeed;
                //}
            }

            // Apply gravity
            moveDirection.y = moveDirection.y - (gravity * Time.fixedDeltaTime);

            controller.Move(moveDirection * speed * Time.fixedDeltaTime);
        }
    }