Esempio n. 1
0
        void Update()
        {
            //Get Input
            bool useKey = Input.GetKey(GlobalSettings.keyUse);

            //IsRiding & pressing -> standUp
            if (isRiding)
            {
                if (useKey && !isPressing && PlayerController.playerController.canMove)
                {
                    lastRide.Use();
                    isRiding = false;
                }
            }
            else
            {
                //Get useable GameObject and maybe use it
                RaycastHit hit;
                if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, range))
                {
                    GameObject hitObject = hit.collider.gameObject;
                    if (hitObject.CompareTag("Useable"))
                    {
                        Useable useable = hitObject.GetComponent <Useable>();
                        useable.ShowControls();

                        if (useKey && !isPressing && PlayerController.playerController.canMove)
                        {
                            isPressing = true;
                            if (useable is Rideable)
                            {
                                lastRide = (Rideable)useable;
                                isRiding = true;
                            }
                            useable.Use();
                        }
                    }
                }
            }

            if (useKey && !isPressing)
            {
                isPressing = true;
            }
            if (!useKey && isPressing)
            {
                isPressing = false;
            }
        }
Esempio n. 2
0
        private IEnumerator RideEnumerator(Transform rideable, Transform newPosition)
        {
            transform.SetParent(rideable);

            if (currentRide == null)
            {
                currentRide            = rideable.GetComponent <Rideable>();
                isSitting              = true;
                isRiding               = true;
                charController.enabled = false;
                yield return(MovePlayer(newPosition));
            }
            else
            {
                yield return(MovePlayer(newPosition));

                currentRide            = null;
                isSitting              = false;
                isRiding               = false;
                charController.enabled = true;
            }
        }