GetInput() private méthode

private GetInput ( ) : Vector2
Résultat Vector2
Exemple #1
0
    void Update()
    {
        if (inputManager.HasInputs())
        {
            LeanLeft  = inputManager.GetInput("LeanLeft");
            LeanRight = inputManager.GetInput("LeanRight");
            ZoomKey   = inputManager.GetInput("Zoom");
        }

        LeanUpdate();

        if (zoomEnabled)
        {
            if (Input.GetKey(ZoomKey))
            {
                MainCamera.fieldOfView = Mathf.Lerp(MainCamera.fieldOfView, ZoomFOV, ZoomSpeed * Time.deltaTime);
                if (WeaponCamera)
                {
                    WeaponCamera.fieldOfView = Mathf.Lerp(MainCamera.fieldOfView, ZoomFOV, ZoomSpeed * Time.deltaTime);
                }
            }
            else
            {
                MainCamera.fieldOfView = Mathf.Lerp(MainCamera.fieldOfView, NormalFOV, ZoomSpeed * Time.deltaTime);
                if (WeaponCamera)
                {
                    WeaponCamera.fieldOfView = Mathf.Lerp(MainCamera.fieldOfView, NormalFOV, ZoomSpeed * Time.deltaTime);
                }
            }
        }
    }
    private void Awake()
    {
        Debug.unityLogger.logEnabled = _isLogEnabled;

        //Few devices limit FPS by default, setting FPS to max possible
        Application.targetFrameRate = 300;

        //Assigning Dependencies
        _uIManager.Init(this);
        _gamePlayController.Init(this, _inputController.GetInput());
        _cameraController.Init(_inputController.GetInput());

        //Handler
        LevelCompleted += OnLevelCompleted;
    }
Exemple #3
0
    void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player") && !isShown && gameManager && inputController)
        {
            char[] hintChars = Hint.ToCharArray();

            if (hintChars.Contains('{') && hintChars.Contains('}'))
            {
                string key = inputController.GetInput(Hint.GetBetween('{', '}')).ToString();
                Hint = Hint.ReplacePart('{', '}', key);
            }

            if (ShowAfter > 0)
            {
                timedShow = true;
            }
            else
            {
                if (!string.IsNullOrEmpty(Hint))
                {
                    gameManager.ShowHint(Hint, TimeShow);
                }
                if (HintSound && soundEffects)
                {
                    soundEffects.clip = HintSound;
                    soundEffects.Play();
                }
                isShown = true;
            }
        }
    }
 void Update()
 {
     if (activePieces)
     {
         inputController.GetInput();
     }
 }
Exemple #5
0
    //Update Camera so its pointing at Target, cater for Camara Zoom and Move
    void Update()
    {
        Vector3 tTargetPosition = Vector3.zero;

        if (Target != null)                 //Keep Camera looking at Parent, if set up
        {
            tTargetPosition = Target.transform.position;
        }
        if (Follow)
        {
            mPolar.Radius   += InputController.GetInput(InputController.Directions.Zoom) * Time.deltaTime * Sensitivity;
            mPolar.Azimuth  += InputController.GetInput(InputController.Directions.ShiftMoveX) * Time.deltaTime * Sensitivity * 10f;
            mPolar.Attitude += InputController.GetInput(InputController.Directions.ShiftMoveY) * Time.deltaTime * Sensitivity * 10f;

            mPolar.Radius   = Mathf.Clamp(mPolar.Radius, 1.5f, 50f);
            mPolar.Azimuth  = Mathf.Clamp(mPolar.Azimuth, -135f, 135);
            mPolar.Attitude = Mathf.Clamp(mPolar.Attitude, 5f, 45f);

            transform.position = mPolar.Vector + tTargetPosition;               //Move camera to now location on Camera plane
        }
        if (Look)
        {
            transform.LookAt(tTargetPosition);                  //Look at parent
        }
    }
Exemple #6
0
    void Update()
    {
        if (inputControl.HasInputs())
        {
            UseItemKey = inputControl.GetInput("Flashlight");
        }

        CanReload = oilPercentage < canReloadPercent;

        if (Inventory.CheckItemInventory(lanternInventoryID) && switcher.currentLightObject == switcherID && !isBlocked)
        {
            if (Input.GetKeyDown(UseItemKey) && !anim.isPlaying && !isPressed)
            {
                if (!isSelected && switcher.currentItem != switcherID)
                {
                    switcher.SelectItem(switcherID);
                }
                else
                {
                    Deselect();
                }

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

        if (isSelected)
        {
            if (oilPercentage > 0)
            {
                oilPercentage -= Time.deltaTime * (100 / oilLifeInSec);

                if (oilPercentage <= reductionFactor)
                {
                    reduceIntensity -= lightReductionRate / 100;
                    reductionFactor -= lightReductionRate;
                    StartCoroutine(Reduce());
                }
            }

            gameManager.UpdateLightPercent(oilPercentage);
        }
        else
        {
            if (!isSelecting)
            {
                LanternLight.gameObject.SetActive(false);
                LanternGO.SetActive(false);
            }
        }

        oilPercentage   = Mathf.Clamp(oilPercentage, 0, 100);
        reductionFactor = Mathf.Clamp(reductionFactor, 0, 100);
        LanternLight.transform.GetChild(0).GetComponent <MeshRenderer>().material.SetColor("_TintColor", FlameTint);
    }
 public virtual void Update()
 {
     HandleInput(
         AcceptingInputs
                     ? InputController.GetInput()
                     : InputPackage.Empty
         );
 }
    private void Update()
    {
        if (GameManager.Instance.GetCurrentState() != this)
        {
            return;
        }

        _inputController?.GetInput();
    }
 // FixedUpdate is called once per physics frame, this is locked to a fixed framerate
 void FixedUpdate()
 {
     mForce.x = InputController.GetInput(InputController.Directions.MoveX);
     mForce.z = InputController.GetInput(InputController.Directions.MoveY);
     mRB.AddForce(mForce * Sensitivity);
     mForce.x = mForce.z = 0f;
     mForce.y = InputController.GetInput(InputController.Directions.Jump);
     mRB.AddForce(mForce, ForceMode.Impulse);
 }
    //Example of how to read the input from central manager
    void Update()
    {
        mMove.x   = InputController.GetInput(InputController.Directions.MoveX);
        mMove.y   = InputController.GetInput(InputController.Directions.MoveY);
        mRotate.x = InputController.GetInput(InputController.Directions.RotateX);
        mRotate.y = InputController.GetInput(InputController.Directions.RotateY);
        float tFire = InputController.GetInput(InputController.Directions.Fire);
        float tZoom = InputController.GetInput(InputController.Directions.Zoom);

        mText.text  = string.Format("Move {0:f2}\n", mMove);
        mText.text += string.Format("Rotate {0:f2}\n", mRotate);
        mText.text += string.Format("Zoom:{0:f2} Fire:{1:f2}", tZoom, tFire);
    }
Exemple #11
0
    void FixedUpdate()
    {
        float tThrust = InputController.GetInput(InputController.Directions.Thrust);
        float tRoll   = InputController.GetInput(InputController.Directions.MoveX);
        float tPitch  = InputController.GetInput(InputController.Directions.MoveY);

        mANI.SetBool("EngineOn", (tThrust > 0f));
        Vector3 tForce = Vector3.zero;

        tForce.y = -Physics.gravity.y * mANI.GetFloat("EngineSpeed") * tThrust * mThrust;
        mANI.SetInteger("Pitch", Mathf.RoundToInt(tPitch));
        mANI.SetInteger("Roll", Mathf.RoundToInt(tRoll));
        tForce.z = tPitch * mThrust;
        tForce.x = tRoll * mThrust;
        mRB.AddForce(tForce, ForceMode.Force);                  //Engine 1.5x G and depends on Rotor speed
    }
    void Update()
    {
        if (inputManager.HasInputs())
        {
            useKey = inputManager.GetInput("Use");
        }

        if (Input.GetKeyDown(useKey) && !isPressed)
        {
            Debug.Log("Use Key Pressed!");
            isPressed = true;
        }
        else if (isPressed)
        {
            isPressed = false;
        }
    }
Exemple #13
0
        /// <summary>
        /// Get string with specified input between two chars, with before and after separators
        /// </summary>
        public static string GetStringWithInput(this string str, char start, char end, char before, char after, InputController input = null)
        {
            if (input == null)
            {
                input = InputController.Instance;
            }

            char[] stringCh = str.ToCharArray();

            if (stringCh.Contains(start) && stringCh.Contains(end))
            {
                string key = input.GetInput(str.RegexBetween(start, end)).ToString();
                return(str.RegexReplace(start, end, before + key + after));
            }

            return(str);
        }
Exemple #14
0
        /// <summary>
        /// Get string with specified input between two chars
        /// </summary>
        public static string GetStringWithInput(this string str, char start, char end, InputController input = null)
        {
            string result = "";

            if (input == null)
            {
                input = InputController.Instance;
            }

            char[] stringCh = str.ToCharArray();

            if (stringCh.Contains(start) && stringCh.Contains(end))
            {
                string key = input.GetInput(str.RegexBetween(start, end)).ToString();
                result = str.RegexReplace(start, end, key);
            }

            return(result);
        }
Exemple #15
0
    void FixedUpdate()
    {
        if (stopped)
        {
            rb.velocity = Vector3.zero;
            return;
        }
        else
        {
            Vector2 playerInput = mInput.GetInput();
            if (playerInput.magnitude == 0)
            {
                playerInput = transform.up;
            }

            transform.up = Vector3.RotateTowards(transform.up, playerInput, rotationSpeed * Time.deltaTime, 0.0f);
            rb.velocity  = transform.up * speed;
        }
    }
Exemple #16
0
    void Update()
    {
        if (inputManager.HasInputs())
        {
            BlowOutKey = inputManager.GetInput("Flashlight");
        }

        CandleFlame.transform.position = FlamePosition.position;

        if (Input.GetKeyDown(BlowOutKey) && !IsPressed && isSelected && !CandleGO.GetComponent <Animation> ().isPlaying&& !IsBlocked)
        {
            CandleGO.GetComponent <Animation>().Play(BlowOutAnimation);
            StopAllCoroutines();
            IsPressed = true;
        }

        if (IsPressed && !(CandleGO.GetComponent <Animation> ().isPlaying))
        {
            CandleGO.SetActive(false);
            IsPressed = false;
        }
    }
Exemple #17
0
    // Update is called once per frame
    protected void Update()
    {
        int tDirection = Mathf.RoundToInt(InputController.GetInput(InputController.Directions.MoveY));

        mAnimator.SetInteger("Direction", tDirection);
        Quaternion tRotation = Quaternion.Euler(0, 0, -InputController.GetInput(InputController.Directions.MoveX) * 180f * Time.deltaTime);

        transform.rotation *= tRotation;
        if (mCoolDown > 0f)
        {
            mCoolDown -= Time.deltaTime;
        }
        if (mCoolDown <= 0f)
        {
            if (InputController.GetInput(InputController.Directions.Fire) > 0f)
            {
                mCoolDown = CoolDown;
                GameObject tShellGO = Instantiate(ShellPrefab);
                tShellGO.transform.rotation = transform.rotation;
                tShellGO.transform.position = transform.position + transform.rotation * (Vector2.up * 0.5f);
            }
        }
    }
    public void FixedUpdate()
    {
        float tThrottle = InputController.GetInput(InputController.Directions.Thrust);
        float tBrake    = InputController.GetInput(InputController.Directions.Brake);
        float tMotor    = maxMotorTorque * (tThrottle - (2f * tBrake));
        float tSteering = maxSteeringAngle * InputController.GetInput(InputController.Directions.MoveX);

        Debug.Log(tMotor);
        foreach (AxleInfo tAxleInfo in axleInfos)
        {
            if (tAxleInfo.Steering)
            {
                tAxleInfo.LeftWheel.steerAngle  = tSteering;
                tAxleInfo.RightWheel.steerAngle = tSteering;
            }
            if (tAxleInfo.Motor)
            {
                tAxleInfo.LeftWheel.motorTorque  = tMotor;
                tAxleInfo.RightWheel.motorTorque = tMotor;
            }
            ApplyLocalPositionToVisuals(tAxleInfo.LeftWheel, tAxleInfo.mLeftWheelRotation);
            ApplyLocalPositionToVisuals(tAxleInfo.RightWheel, tAxleInfo.mRightWheelRotation);
        }
    }
Exemple #19
0
    void Update()
    {
        if (inputControl.HasInputs())
        {
            AttackKey = inputControl.GetInput("Fire");
        }

        if (Inventory.CheckItemInventory(ItemInventoryID) && scriptManager.ScriptGlobalState && isSelected && !wallHit && !isBlocked)
        {
            if (Input.GetKeyDown(AttackKey) && !anim.isPlaying)
            {
                PlaySound(SwaySound, SwayVolume);
                anim.Play(AttackAnim);
                StartCoroutine(SwayMelee(SwayKickback, SwaySpeed));

                Ray playerAim = cam.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));

                if (Physics.Raycast(playerAim, out RaycastHit hit, HitDistance, HitLayer))
                {
                    StartCoroutine(Hit(hit, playerAim.direction));
                }
            }
        }
    }
    //Update Camera so its pointing at Target, cater for Camara Zoom and Move
    void Update()
    {
        if (AutoHeight)
        {
            Quaternion tYrotation = Quaternion.identity;
            Vector2    tVelocity  = new Vector2(mRB.velocity.x, mRB.velocity.z);
            if (tVelocity.magnitude > 0.1f)
            {
                tYrotation = Quaternion.Euler(0, Mathf.Atan2(mRB.velocity.x, mRB.velocity.z) * Mathf.Rad2Deg, 0); //Isolate Rotation around y
            }
            Vector3 tAdjustedPosition = tYrotation * mPosition;                                                   //Rotate Camera around Y
            tAdjustedPosition   += Target.transform.position;
            tAdjustedPosition.y += Terrain.SampleHeight(tAdjustedPosition);
            transform.position   = tAdjustedPosition;
        }
        else
        {
            mPolar.Radius   += InputController.GetInput(InputController.Directions.Zoom) * Time.deltaTime * Sensitivity;
            mPolar.Azimuth  += InputController.GetInput(InputController.Directions.ShiftMoveX) * Time.deltaTime * Sensitivity * 10f;
            mPolar.Attitude += InputController.GetInput(InputController.Directions.ShiftMoveY) * Time.deltaTime * Sensitivity * 10f;

            mPolar.Radius      = Mathf.Clamp(mPolar.Radius, 1.5f, 50f);
            mPolar.Azimuth     = Mathf.Clamp(mPolar.Azimuth, -135f, 135);
            mPolar.Attitude    = Mathf.Clamp(mPolar.Attitude, 5f, 45f);
            transform.position = mPolar.Vector + Target.transform.position;;            //Move camera to now location on Camera plane
        }

        if (Target == null)         //Keep Camera looking at Parent
        {
            Debug.Log("No Parent to look at");
        }
        else
        {
            transform.LookAt(Target.transform.position);        //Look at parent
        }
    }
Exemple #21
0
    void Update()
    {
        if (inputControl.HasInputs())
        {
            UseItemKey = inputControl.GetInput("Flashlight");
        }

        CanReload = oilPercentage < canReloadPercent;

        if (Inventory.CheckItemIDInventory(lanternInventoryID) && switcher.currentLightObject == switcherID)
        {
            if (Input.GetKeyDown(UseItemKey) && !anim.isPlaying && !isPressed)
            {
                if (!isSelected && switcher.currentItem != switcherID)
                {
                    switcher.selectItem(switcherID);
                }
                else
                {
                    Deselect();
                }
                isPressed = true;
            }
            else if (isPressed)
            {
                isPressed = false;
            }
        }

        if (isSelected)
        {
            if (oilPercentage > 0)
            {
                oilPercentage -= Time.deltaTime * (100 / oilLifeInSec);

                if (oilPercentage <= reductionFactor)
                {
                    reduceIntensity -= lightReductionRate / 100;
                    reductionFactor -= lightReductionRate;
                    StartCoroutine(Reduce());

                    int spriteInt = Mathf.RoundToInt(reductionFactor + lightReductionRate);
                    currentSprite = spritePrefix + spriteInt;
                }
            }

            OilSprite.sprite = Resources.Load <Sprite>("Icons/OilPercentagle/" + currentSprite);
        }
        else
        {
            if (!isSelecting)
            {
                LanternLight.gameObject.SetActive(false);
                LanternGO.SetActive(false);
            }
        }

        if (showSprite)
        {
            OilSprite.color = UIFader.GetUIColor();
        }

        oilPercentage   = Mathf.Clamp(oilPercentage, 0, 100);
        reductionFactor = Mathf.Clamp(reductionFactor, 0, 100);
        LanternLight.transform.GetChild(0).GetComponent <MeshRenderer>().material.SetColor("_TintColor", FlameTint);
    }
Exemple #22
0
    void Update()
    {
        inventory = GetComponent <ScriptManager>().GetScript <Inventory>();

        if (inputManager.HasInputs())
        {
            UseKey    = inputManager.GetInput("Use");
            PickupKey = inputManager.GetInput("Pickup").ToString();
        }

        if (Input.GetKey(UseKey) && RaycastObject && !isPressed && !isHeld && !inUse)
        {
            Interact();
            isPressed = true;
        }

        if (Input.GetKeyUp(UseKey) && isPressed)
        {
            isPressed = false;
        }

        Ray        playerAim = playerCam.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
        RaycastHit hit;

        if (Physics.Raycast(playerAim, out hit, RayLength, cullLayers))
        {
            RaycastTag = hit.collider.gameObject.tag;
            if (hit.collider.gameObject.layer == LayerMask.NameToLayer(InteractLayer))
            {
                RaycastObject = hit.collider.gameObject;
                correctLayer  = true;

                if (RaycastObject.GetComponent <DynamicObject>())
                {
                    dynamic = RaycastObject.GetComponent <DynamicObject>();
                }
                else
                {
                    dynamic = null;
                }

                if (RaycastObject.GetComponent <CrosshairReticle>())
                {
                    CrosshairReticle ChangeReticle = RaycastObject.GetComponent <CrosshairReticle>();
                    if (dynamic)
                    {
                        if (dynamic.useType != DynamicObject.type.Locked)
                        {
                            interactCrosshair = ChangeReticle.interactSprite;
                            interactSize      = ChangeReticle.size;
                        }
                    }
                    else
                    {
                        interactCrosshair = ChangeReticle.interactSprite;
                        interactSize      = ChangeReticle.size;
                    }
                }

                useTexture = true;

                if (LastRaycastObject)
                {
                    if (!(LastRaycastObject == RaycastObject))
                    {
                        ResetCrosshair();
                    }
                }
                LastRaycastObject = RaycastObject;

                if (!inUse)
                {
                    if (dynamic)
                    {
                        if (dynamic.useType == DynamicObject.type.Locked)
                        {
                            if (dynamic.CheckHasKey())
                            {
                                gameManager.ShowInteractSprite(1, UnlockText, UseKey.ToString());
                            }
                            else
                            {
                                gameManager.ShowInteractSprite(1, UseText, UseKey.ToString());
                            }
                        }
                        else
                        {
                            gameManager.ShowInteractSprite(1, UseText, UseKey.ToString());
                        }
                    }
                    else
                    {
                        if (RaycastObject.GetComponent <DynamicObjectPlank>())
                        {
                            gameManager.ShowInteractSprite(1, RemoveText, UseKey.ToString());
                        }
                        else if (!(RaycastTag == "OnlyGrab"))
                        {
                            gameManager.ShowInteractSprite(1, UseText, UseKey.ToString());
                        }
                    }
                    if (RaycastTag == "OnlyGrab")
                    {
                        gameManager.ShowInteractSprite(1, GrabText, PickupKey);
                    }
                    else if (RaycastTag == "Grab")
                    {
                        gameManager.ShowInteractSprite(1, UseText, UseKey.ToString());
                        gameManager.ShowInteractSprite(2, GrabText, PickupKey);
                    }
                    else if (RaycastTag == "Paper")
                    {
                        gameManager.ShowInteractSprite(1, ExamineText, PickupKey);
                    }
                    if (RaycastObject.GetComponent <ExamineItem>())
                    {
                        if (RaycastObject.GetComponent <ExamineItem>().isUsable)
                        {
                            gameManager.ShowInteractSprite(1, UseText, UseKey.ToString());
                            gameManager.ShowInteractSprite(2, ExamineText, PickupKey);
                        }
                        else
                        {
                            gameManager.ShowInteractSprite(1, ExamineText, PickupKey);
                        }
                    }
                }
            }
            else if (RaycastObject)
            {
                correctLayer = false;
            }
        }
        else if (RaycastObject)
        {
            correctLayer = false;
        }

        if (!correctLayer)
        {
            ResetCrosshair();
            useTexture    = false;
            RaycastTag    = null;
            RaycastObject = null;
            dynamic       = null;
        }

        if (!RaycastObject)
        {
            gameManager.HideSprites(spriteType.Interact);
            useTexture = false;
            dynamic    = null;
        }

        CrosshairUpdate();
    }
    void Update()
    {
        if (inputManager.HasInputs())
        {
            UseKey = inputManager.GetInput("Use");
        }

        //Prevent Interact Dynamic Object when player is holding other object
        otherHeld = GetComponent <DragRigidbody> ().CheckHold();

        if (objectRaycast && !otherHeld && isDynamic && !release)
        {
            if (Input.GetKey(UseKey))
            {
                isHeld = true;
            }
            else if (isHeld)
            {
                isHeld = false;
            }
        }

        if (isHeld)
        {
            if (!firstGrab)
            {
                grabObject();
            }
            else
            {
                if (isDoor)
                {
                    grabDoor();
                }
                else if (!isLever && !isValve)
                {
                    grabDrawer();
                }
                else if (isLever && !isValve)
                {
                    grabLever();
                }
                else if (isValve)
                {
                    grabValve();
                }
            }
        }
        else if (firstGrab)
        {
            Release();
        }

        if (isHeld)
        {
            gameManager.MouseLookState(false);
            delay.isEnabled = false;
            if (objectRaycast && objectRaycast.GetComponent <DynamicObject> ())
            {
                objectRaycast.GetComponent <DynamicObject> ().isHolding = true;
            }
            distance = Vector3.Distance(objectRaycast.transform.position, transform.root.position);
        }
        else
        {
            gameManager.MouseLookState(true);
            if (objectRaycast && objectRaycast.GetComponent <DynamicObject> ())
            {
                objectRaycast.GetComponent <DynamicObject> ().isHolding = false;
            }
            release  = false;
            distance = 0;
        }

        if (distance >= 3)
        {
            release = true;
            isHeld  = false;
            Release();
        }

        mouse_x      = Input.GetAxis("Mouse X") * (moveDoorSpeed * 10);
        mouse_y      = Input.GetAxis("Mouse Y");
        mouselever_y = Input.GetAxis("Mouse Y") * (moveLeverSpeed * 10);

        Ray        playerAim = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
        RaycastHit hit;

        if (Physics.Raycast(playerAim, out hit, RayLength, CullLayers) && !isHeld)
        {
            if (hit.collider.gameObject.layer == LayerMask.NameToLayer(InteractLayer))
            {
                objectRaycast = hit.collider.gameObject;
                if (objectRaycast.GetComponent <DynamicObject> () && objectRaycast.tag == DynamicObjectTag)
                {
                    dynamic   = objectRaycast.GetComponent <DynamicObject> ();
                    isDynamic = true;
                }
                else
                {
                    isDynamic = false;
                }
            }
            else if (objectRaycast && !isHeld && !firstGrab)
            {
                isDoor        = false;
                isLever       = false;
                isValve       = false;
                objectRaycast = null;
            }
        }
        else if (objectRaycast && !isHeld && !firstGrab)
        {
            isDoor        = false;
            isLever       = false;
            isValve       = false;
            objectRaycast = null;
        }

        if (objectRaycast && !isHeld && joint)
        {
            if (isLever || isDoor)
            {
                motor.targetVelocity = 0;
                joint.useMotor       = false;
                joint.motor          = motor;
            }
        }

        if (dynamic)
        {
            dynamic.isHeld = isHeld;
        }
    }
Exemple #24
0
    void Update()
    {
        if (inputManager.HasInputs())
        {
            useKey    = inputManager.GetInput("Use");
            grabKey   = inputManager.GetInput("Pickup");
            rotateKey = inputManager.GetInput("Fire");
        }

        //Prevent Interact Dynamic Object when player is holding other object
        otherHeld = GetComponent <DragRigidbody> ().CheckHold();

        if (gameManager.isPaused)
        {
            return;
        }

        if (objectRaycast && !antiSpam && firstExamine && firstExamine.examineType != InteractiveItem.ExamineType.None)
        {
            if (Input.GetKeyDown(grabKey) && !isPressed && !otherHeld)
            {
                isPressed   = true;
                isExamining = !isExamining;
            }
            else if (isPressed)
            {
                isPressed = false;
            }
        }

        if (isExamining)
        {
            if (!isObjectHeld)
            {
                FirstPhase();
                tryExamine = true;
            }
            else
            {
                HoldObject();
            }
        }
        else if (isObjectHeld)
        {
            if (!secondExamine)
            {
                DropObject();
            }
            else
            {
                SecondExaminedObject(false);
                isExamining = true;
            }
        }

        PlayerAim = PlayerCam.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));

        if (!isInspect)
        {
            if (Physics.Raycast(PlayerAim, out RaycastHit hit, pickupRange, CullLayers))
            {
                if (hit.collider.gameObject.layer == LayerMask.NameToLayer(InteractLayer))
                {
                    if (hit.collider.gameObject.GetComponent <InteractiveItem>())
                    {
                        objectRaycast = hit.collider.gameObject;
                        firstExamine  = objectRaycast.GetComponent <InteractiveItem>();
                    }
                    else
                    {
                        if (!tryExamine)
                        {
                            objectRaycast = null;
                            firstExamine  = null;
                        }
                    }
                }
                else
                {
                    if (!tryExamine)
                    {
                        objectRaycast = null;
                        firstExamine  = null;
                    }
                }
            }
            else
            {
                if (!tryExamine)
                {
                    objectRaycast = null;
                    firstExamine  = null;
                }
            }
        }
    void Update()
    {
        if (inputManager.HasInputs())
        {
            grabKey    = inputManager.GetInput("Pickup");
            rotateKey  = inputManager.GetInput("Fire");
            examineKey = inputManager.GetInput("Examine");
        }

        //Prevent Interact Dynamic Object when player is holding other object
        otherHeld = GetComponent <DragRigidbody> ().CheckHold();

        if (gameManager.isPaused)
        {
            return;
        }

        if (objectRaycast && !antiSpam && examinedItem)
        {
            if (Input.GetKeyDown(grabKey) && !isPressed && !otherHeld)
            {
                isPressed  = true;
                isExaminig = !isExaminig;
            }
            else if (isPressed)
            {
                isPressed = false;
            }
        }

        if (isExaminig)
        {
            if (!isObjectHeld)
            {
                firstGrab();
                tryExamine = true;
            }
            else
            {
                holdObject();
            }
        }
        else if (isObjectHeld)
        {
            dropObject();
        }

        RaycastHit hit;

        playerAim = playerCam.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));

        if (Physics.Raycast(playerAim, out hit, PickupRange, CullLayers))
        {
            if (hit.collider.gameObject.layer == LayerMask.NameToLayer(InteractLayer))
            {
                if (hit.collider.tag == TagExamine || hit.collider.tag == TagExaminePaper)
                {
                    objectRaycast = hit.collider.gameObject;
                    if (objectRaycast.GetComponent <ExamineItem> ())
                    {
                        examinedItem = objectRaycast.GetComponent <ExamineItem> ();
                    }
                }
                else
                {
                    if (!tryExamine)
                    {
                        objectRaycast = null;
                        examinedItem  = null;
                    }
                }
            }
            else
            {
                if (!tryExamine)
                {
                    objectRaycast = null;
                    examinedItem  = null;
                }
            }
        }
        else
        {
            if (!tryExamine)
            {
                objectRaycast = null;
                examinedItem  = null;
            }
        }

        float rotationInputX = 0.0f;
        float rotationInputY = 0.0f;

        float x = Input.GetAxis("Mouse X");
        float y = Input.GetAxis("Mouse Y");

        if (Mathf.Abs(x) > rotationDeadzone)
        {
            rotationInputX = -(x * rotateSpeed);
        }

        if (Mathf.Abs(y) > rotationDeadzone)
        {
            rotationInputY = (y * rotateSpeed);
        }

        if (objectHeld && isObjectHeld)
        {
            if (Input.GetKey(rotateKey) && !isReading)
            {
                objectHeld.transform.Rotate(playerCam.transform.up, rotationInputX, Space.World);
                objectHeld.transform.Rotate(playerCam.transform.right, rotationInputY, Space.World);
            }

            if (Input.GetKey(examineKey) && !isPaper)
            {
                gameManager.ShowHint(examineName);
            }

            if (isPaper)
            {
                if (Input.GetKeyDown(examineKey) && !isPressedRead)
                {
                    isPressedRead = true;
                    isReading     = !isReading;
                }
                else if (isPressedRead)
                {
                    isPressedRead = false;
                }

                if (isReading)
                {
                    ExamineItem examine = objectRaycast.GetComponent <ExamineItem>();
                    paperText.text     = examine.paperReadText;
                    paperText.fontSize = examine.textSize;
                    paperUI.SetActive(true);
                }
                else
                {
                    paperUI.SetActive(false);
                }
            }
        }
    }
Exemple #26
0
    void Update()
    {
        inventory = GetComponent <ScriptManager>().GetScript <Inventory>();

        if (inputManager.HasInputs())
        {
            UseKey    = inputManager.GetInput("Use");
            PickupKey = inputManager.GetInput("Pickup");
        }

        if (Input.GetKey(UseKey) && RaycastObject && !isPressed && !isHeld && !inUse)
        {
            Interact(RaycastObject);
            isPressed = true;
        }

        if (Input.GetKeyUp(UseKey) && isPressed)
        {
            isPressed = false;
        }

        Ray playerAim = mainCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));

        if (Physics.Raycast(playerAim, out RaycastHit hit, RaycastRange, cullLayers))
        {
            if (hit.collider.gameObject.layer == LayerMask.NameToLayer(InteractLayer))
            {
                if (hit.collider.gameObject != RaycastObject)
                {
                    gameManager.HideSprites(hideType.Interact);
                }

                RaycastObject = hit.collider.gameObject;
                RaycastTag    = hit.collider.tag;
                correctLayer  = true;

                if (RaycastObject.GetComponent <InteractiveItem>())
                {
                    interactItem = RaycastObject.GetComponent <InteractiveItem>();
                }
                else
                {
                    interactItem = null;
                }

                if (RaycastObject.GetComponent <DynamicObject>())
                {
                    dynamicObj = RaycastObject.GetComponent <DynamicObject>();
                }
                else
                {
                    dynamicObj = null;
                }

                if (RaycastObject.GetComponent <UIObjectInfo>())
                {
                    objectInfo = RaycastObject.GetComponent <UIObjectInfo>();
                }
                else
                {
                    objectInfo = null;
                }

                if (RaycastObject.GetComponent <CrosshairReticle>())
                {
                    CrosshairReticle ChangeReticle = RaycastObject.GetComponent <CrosshairReticle>();
                    if (dynamicObj)
                    {
                        if (dynamicObj.useType != Type_Use.Locked)
                        {
                            interactCrosshair = ChangeReticle.interactSprite;
                            interactSize      = ChangeReticle.size;
                        }
                    }
                    else
                    {
                        interactCrosshair = ChangeReticle.interactSprite;
                        interactSize      = ChangeReticle.size;
                    }
                }

                if (LastRaycastObject)
                {
                    if (!(LastRaycastObject == RaycastObject))
                    {
                        ResetCrosshair();
                    }
                }
                LastRaycastObject = RaycastObject;

                if (objectInfo && !string.IsNullOrEmpty(objectInfo.objectTitle))
                {
                    gameManager.ShowInteractInfo(objectInfo.objectTitle);
                }

                if (!inUse)
                {
                    if (dynamicObj)
                    {
                        if (dynamicObj.useType == Type_Use.Locked)
                        {
                            if (dynamicObj.CheckHasKey())
                            {
                                gameManager.ShowInteractSprite(1, UnlockText, UseKey);
                            }
                            else
                            {
                                if (dynamicObj.interactType == Type_Interact.Mouse)
                                {
                                    gameManager.ShowInteractSprite(1, DragText, UseKey);
                                }
                                else
                                {
                                    gameManager.ShowInteractSprite(1, UseText, UseKey);
                                }
                            }
                        }
                        else
                        {
                            if (dynamicObj.interactType == Type_Interact.Mouse)
                            {
                                gameManager.ShowInteractSprite(1, DragText, UseKey);
                            }
                            else
                            {
                                gameManager.ShowInteractSprite(1, UseText, UseKey);
                            }
                        }
                    }
                    else
                    {
                        if (interactItem)
                        {
                            if (interactItem.showItemName && !string.IsNullOrEmpty(interactItem.ItemName))
                            {
                                gameManager.ShowInteractInfo(interactItem.ItemName);
                            }

                            if (RaycastTag != "GrabUse")
                            {
                                if (interactItem.ItemType == InteractiveItem.Type.OnlyExamine)
                                {
                                    gameManager.ShowInteractSprite(1, ExamineText, PickupKey);
                                }
                                else if (interactItem.ItemType == InteractiveItem.Type.InteractObject)
                                {
                                    if (interactItem.examineType != InteractiveItem.ExamineType.None)
                                    {
                                        gameManager.ShowInteractSprite(1, UseText, UseKey);
                                        gameManager.ShowInteractSprite(2, ExamineText, PickupKey);
                                    }
                                    else
                                    {
                                        gameManager.ShowInteractSprite(1, UseText, UseKey);
                                    }
                                }
                                else if (interactItem.examineType != InteractiveItem.ExamineType.None && interactItem.ItemType != InteractiveItem.Type.InteractObject)
                                {
                                    gameManager.ShowInteractSprite(1, TakeText, UseKey);
                                    gameManager.ShowInteractSprite(2, ExamineText, PickupKey);
                                }
                                else if (interactItem.examineType == InteractiveItem.ExamineType.Paper)
                                {
                                    gameManager.ShowInteractSprite(1, ExamineText, PickupKey);
                                }
                                else
                                {
                                    gameManager.ShowInteractSprite(1, TakeText, UseKey);
                                }
                            }
                            else
                            {
                                if (interactItem.ItemType != InteractiveItem.Type.OnlyExamine)
                                {
                                    gameManager.ShowInteractSprite(1, TakeText, UseKey);
                                    gameManager.ShowInteractSprite(2, GrabText, PickupKey);
                                }
                            }
                        }
                        else if (RaycastObject.GetComponent <DynamicObjectPlank>())
                        {
                            gameManager.ShowInteractSprite(1, RemoveText, UseKey);
                        }
                        else if (RaycastTag == "Grab")
                        {
                            gameManager.ShowInteractSprite(1, GrabText, PickupKey);
                        }
                        else if (objectInfo)
                        {
                            gameManager.ShowInteractSprite(1, objectInfo.useText, UseKey);
                        }
                        else
                        {
                            gameManager.ShowInteractSprite(1, UseText, UseKey);
                        }
                    }
                }

                CrosshairChange(true);
            }
            else if (RaycastObject)
            {
                correctLayer = false;
            }
        }
    void Update()
    {
        if (inputManager && inputManager.HasInputs())
        {
            ForwardKey  = inputManager.GetInput("Forward");
            BackwardKey = inputManager.GetInput("Backward");
            LeftKey     = inputManager.GetInput("Left");
            RightKey    = inputManager.GetInput("Right");
            JumpKey     = inputManager.GetInput("Jump");
            RunKey      = inputManager.GetInput("Run");
            CrouchKey   = inputManager.GetInput("Crouch");
        }

        velMagnitude = controller.velocity.magnitude;
        //float inputX = Input.GetAxis("Horizontal");
        //float inputY = Input.GetAxis("Vertical");

        if (controllable)
        {
            if (Input.GetKey(ForwardKey))
            {
                GetKeyAxis("Y", "fw", 1);
            }
            else
            {
                GetKeyAxis("Y", "fw", 0);
            }

            if (Input.GetKey(BackwardKey))
            {
                GetKeyAxis("Y", "bw", -1);
            }
            else
            {
                GetKeyAxis("Y", "bw", 0);
            }

            if (Input.GetKey(LeftKey))
            {
                GetKeyAxis("X", "l", -1);
            }
            else
            {
                GetKeyAxis("X", "l", 0);
            }

            if (Input.GetKey(RightKey))
            {
                GetKeyAxis("X", "r", 1);
            }
            else
            {
                GetKeyAxis("X", "r", 0);
            }
        }
        else
        {
            GetKeyAxis("Y", "fw", 0);
            GetKeyAxis("Y", "bw", 0);
            GetKeyAxis("X", "l", 0);
            GetKeyAxis("X", "r", 0);
        }

        float inputModifyFactor = (inputX != 0.0f && inputY != 0.0f) ? .7071f : 1.0f;

        if (onLadder)
        {
            LadderUpdate();
            highestPoint = transform.position.y;
            run          = false;
            fallDistance = 0.0f;
            grounded     = false;
            armsAnimations.CrossFade(armsIdleAnimation);
            cameraAnimations.CrossFade(idleAnimation);
            return;
        }

        if (grounded)
        {
            gravity = baseGravity;

            if (Physics.Raycast(transform.position, -Vector3.up, out hit, rayDistance))
            {
                float hitangle = Vector3.Angle(hit.normal, Vector3.up);
                if (hitangle > slideLimit)
                {
                    sliding = true;
                }
                else
                {
                    sliding = false;
                }
            }

            if (canRun && state == 0)
            {
                if (Input.GetKey(RunKey) && Input.GetKey(ForwardKey) && !Input.GetKey(ZoomKey) && !footsteps.inWater && controllable)
                {
                    run = true;
                }
                else
                {
                    run = false;
                }
            }

            if (falling)
            {
                if (state == 2)
                {
                    fallingDamageThreshold = crouchFallTreshold;
                }
                else
                {
                    fallingDamageThreshold = standFallTreshold;
                }

                falling      = false;
                fallDistance = highestPoint - currentPosition.y;
                if (fallDistance > fallingDamageThreshold)
                {
                    ApplyFallingDamage(fallDistance);
                }

                if (fallDistance < fallingDamageThreshold && fallDistance > 0.1f)
                {
                    if (state < 2)
                    {
                        footsteps.JumpLand();
                    }
                    StartCoroutine(FallCamera(new Vector3(7, Random.Range(-1.0f, 1.0f), 0), new Vector3(3, Random.Range(-0.5f, 0.5f), 0), 0.15f));
                }
            }

            if (sliding)
            {
                Vector3 hitNormal = hit.normal;
                moveDirection = new Vector3(hitNormal.x, -hitNormal.y, hitNormal.z);
                Vector3.OrthoNormalize(ref hitNormal, ref moveDirection);
                moveDirection *= slideSpeed;
            }
            else
            {
                if (state == 0)
                {
                    if (run)
                    {
                        speed = runSpeed;
                    }
                    else if (Input.GetKey(ZoomKey))
                    {
                        speed = crouchSpeed;
                    }
                    else if (!footsteps.inWater)
                    {
                        speed = walkSpeed;
                    }
                    else
                    {
                        speed = inWaterSpeed;
                    }
                }
                else if (state == 1)
                {
                    speed = crouchSpeed;
                    run   = false;
                }
                else if (state == 2)
                {
                    speed = proneSpeed;
                    run   = false;
                }

                if (Cursor.lockState == CursorLockMode.Locked)
                {
                    moveDirection = new Vector3(inputX * inputModifyFactor, -antiBumpFactor, inputY * inputModifyFactor);
                }
                else
                {
                    moveDirection = new Vector3(0, -antiBumpFactor, 0);
                }

                moveDirection  = transform.TransformDirection(moveDirection);
                moveDirection *= speed;

                if (controllable)
                {
                    if (!Input.GetKey(JumpKey))
                    {
                        jumpTimer++;
                    }
                    else if (jumpTimer >= antiBunnyHopFactor)
                    {
                        jumpTimer = 0;
                        if (state == 0)
                        {
                            if (!footsteps.inWater)
                            {
                                moveDirection.y = jumpSpeed;
                            }
                            else
                            {
                                moveDirection.y = inWaterJumpSpeed;
                            }
                        }

                        if (state > 0)
                        {
                            if (CheckDistance() > 1.6f)
                            {
                                state = 0;
                            }
                        }
                    }
                }
            }
        }
        else
        {
            currentPosition = transform.position;
            if (currentPosition.y > lastPosition.y)
            {
                highestPoint = transform.position.y;
                falling      = true;
            }

            if (!falling)
            {
                highestPoint = transform.position.y;
                falling      = true;
            }

            if (airControl)
            {
                moveDirection.x = inputX * speed;
                moveDirection.z = inputY * speed;
                moveDirection   = transform.TransformDirection(moveDirection);
            }
        }

        if (grounded)
        {
            if (!run && velMagnitude > crouchSpeed)
            {
                armsAnimations[armsWalkAnimation].speed = velMagnitude / adjustAnimSpeed;
                armsAnimations.CrossFade(armsWalkAnimation);
                cameraAnimations.CrossFade(walkAnimation);
            }
            else if (run && velMagnitude > walkSpeed)
            {
                armsAnimations.CrossFade(armsRunAnimation);
                cameraAnimations.CrossFade(runAnimation);
            }
            else if (velMagnitude < crouchSpeed)
            {
                armsAnimations.CrossFade(armsIdleAnimation);
                cameraAnimations.CrossFade(idleAnimation);
            }
        }
        else
        {
            armsAnimations.CrossFade(armsIdleAnimation);
            cameraAnimations.CrossFade(idleAnimation);
            run = false;
        }

        if (Input.GetKeyDown(CrouchKey) && !footsteps.inWater && controllable)
        {
            if (state == 0)
            {
                state = 1;
            }
            else if (state > 0)
            {
                if (CheckDistance() > 1.6f)
                {
                    state = 0;
                }
            }
        }

        if (state == 0)           //Stand Position
        {
            controller.height = 2.0f;
            controller.center = new Vector3(0, 0, 0);

            if (cameraGO.localPosition.y > camNormalHeight)
            {
                cameraGO.localPosition = new Vector3(cameraGO.localPosition.x, camNormalHeight, cameraGO.localPosition.z);
            }
            else if (cameraGO.localPosition.y < camNormalHeight)
            {
                cameraGO.localPosition = new Vector3(cameraGO.localPosition.x, cameraGO.localPosition.y + Time.deltaTime * transitionSpeed, cameraGO.localPosition.z);
            }
        }
        else if (state == 1)             //Crouch Position
        {
            controller.height = 1.4f;
            controller.center = new Vector3(0, -0.3f, 0);

            if (cameraGO.localPosition.y != camCrouchHeight)
            {
                if (cameraGO.localPosition.y > camCrouchHeight)
                {
                    cameraGO.localPosition = new Vector3(cameraGO.localPosition.x, cameraGO.localPosition.y - Time.deltaTime * transitionSpeed, cameraGO.localPosition.z);
                }
                if (cameraGO.localPosition.y < camCrouchHeight)
                {
                    cameraGO.localPosition = new Vector3(cameraGO.localPosition.x, cameraGO.localPosition.y + Time.deltaTime * transitionSpeed, cameraGO.localPosition.z);
                }
            }
        }
        else if (state == 2)     //Prone Position
        {
            controller.height = 0.6f;
            controller.center = new Vector3(0, -0.7f, 0);

            if (cameraGO.localPosition.y < camProneHeight)
            {
                cameraGO.localPosition = new Vector3(cameraGO.localPosition.x, camProneHeight, cameraGO.localPosition.z);
            }
            else if (cameraGO.localPosition.y > camProneHeight)
            {
                cameraGO.localPosition = new Vector3(cameraGO.localPosition.x, cameraGO.localPosition.y - Time.deltaTime * (transitionSpeed + 1), cameraGO.localPosition.z);
            }
        }


        moveDirection.y -= gravity * Time.deltaTime;
        grounded         = (controller.Move(moveDirection * Time.deltaTime) & CollisionFlags.Below) != 0;
    }
 void Update()
 {
     nextMove = inputManager.GetInput();
 }
Exemple #29
0
    void Update()
    {
        if (inputManager.HasInputs())
        {
            UseItemKey = inputManager.GetInput("Flashlight");
        }

        CanReload = batteryPercentage < canReloadPercent;

        if (inventory.CheckItemInventory(FlashlightInventoryID) && !isReloading && switcher.currentLightObject == switcherID && !isBlocked)
        {
            if (Input.GetKeyDown(UseItemKey) && !AnimationComp.isPlaying && !isPressed)
            {
                if (!isSelected && switcher.currentItem != switcherID)
                {
                    switcher.SelectItem(switcherID);
                }
                else
                {
                    Deselect();
                }

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

        if (scare && !AnimationComp.isPlaying)
        {
            scare = false;
        }

        if (isSelected && !noPower && !scare)
        {
            gameManager.UpdateLightPercent(batteryPercentage);
        }

        if (isOn)
        {
            LightObject.enabled = true;
            batteryPercentage  -= Time.deltaTime * (100 / batteryLifeInSec);
        }
        else
        {
            LightObject.enabled = false;
        }

        batteryPercentage = Mathf.Clamp(batteryPercentage, 0, 100);

        if (batteryPercentage > 95.0f)
        {
            LightObject.intensity = Mathf.Lerp(LightObject.intensity, 1, Time.deltaTime);
        }
        else if (batteryPercentage <= 95.0f && batteryPercentage > 90.0f)
        {
            LightObject.intensity = Mathf.Lerp(LightObject.intensity, 0.95f, Time.deltaTime);
        }
        else if (batteryPercentage <= 90.0f && batteryPercentage > 85.0f)
        {
            LightObject.intensity = Mathf.Lerp(LightObject.intensity, 0.9f, Time.deltaTime);
        }
        else if (batteryPercentage <= 85.0f && batteryPercentage > 80.0f)
        {
            LightObject.intensity = Mathf.Lerp(LightObject.intensity, 0.85f, Time.deltaTime);
        }
        else if (batteryPercentage <= 80.0f && batteryPercentage > 75.0f)
        {
            LightObject.intensity = Mathf.Lerp(LightObject.intensity, 0.8f, Time.deltaTime);
        }
        else if (batteryPercentage <= 75.0f && batteryPercentage > 70.0f)
        {
            LightObject.intensity = Mathf.Lerp(LightObject.intensity, 0.75f, Time.deltaTime);
        }
        else if (batteryPercentage <= 70.0f && batteryPercentage > 65.0f)
        {
            LightObject.intensity = Mathf.Lerp(LightObject.intensity, 0.7f, Time.deltaTime);
        }
        else if (batteryPercentage <= 65.0f && batteryPercentage > 60.0f)
        {
            LightObject.intensity = Mathf.Lerp(LightObject.intensity, 0.65f, Time.deltaTime);
        }
        else if (batteryPercentage <= 60.0f && batteryPercentage > 55.0f)
        {
            LightObject.intensity = Mathf.Lerp(LightObject.intensity, 0.6f, Time.deltaTime);
        }
        else if (batteryPercentage <= 55.0f && batteryPercentage > 50.0f)
        {
            LightObject.intensity = Mathf.Lerp(LightObject.intensity, 0.55f, Time.deltaTime);
        }
        else if (batteryPercentage <= 50.0f && batteryPercentage > 45.0f)
        {
            LightObject.intensity = Mathf.Lerp(LightObject.intensity, 0.5f, Time.deltaTime);
        }
        else if (batteryPercentage <= 45.0f && batteryPercentage > 40.0f)
        {
            LightObject.intensity = Mathf.Lerp(LightObject.intensity, 0.45f, Time.deltaTime);
        }
        else if (batteryPercentage <= 40.0f && batteryPercentage > 35.0f)
        {
            LightObject.intensity = Mathf.Lerp(LightObject.intensity, 0.4f, Time.deltaTime);
        }
        else if (batteryPercentage <= 35.0f && batteryPercentage > 30.0f)
        {
            LightObject.intensity = Mathf.Lerp(LightObject.intensity, 0.35f, Time.deltaTime);
        }
        else if (batteryPercentage <= 30.0f && batteryPercentage > 25.0f)
        {
            LightObject.intensity = Mathf.Lerp(LightObject.intensity, 0.3f, Time.deltaTime);
        }
        else if (batteryPercentage <= 25.0f && batteryPercentage > 20.0f)
        {
            LightObject.intensity = Mathf.Lerp(LightObject.intensity, 0.25f, Time.deltaTime);
        }
        else if (batteryPercentage <= 20.0f && batteryPercentage > 15.0f)
        {
            LightObject.intensity = Mathf.Lerp(LightObject.intensity, 0.2f, Time.deltaTime);
        }
        else if (batteryPercentage <= 15.0f && batteryPercentage > 10.0f)
        {
            LightObject.intensity = Mathf.Lerp(LightObject.intensity, 0.15f, Time.deltaTime);
        }
        else if (batteryPercentage <= 10.0f && batteryPercentage > 5.0f)
        {
            LightObject.intensity = Mathf.Lerp(LightObject.intensity, 0.1f, Time.deltaTime);
        }
        else if (batteryPercentage <= 5.0f && batteryPercentage > 1.0f)
        {
            LightObject.intensity = Mathf.Lerp(LightObject.intensity, 0.05f, Time.deltaTime);
        }
        else if (batteryPercentage <= 1.0f)
        {
            if (!AnimationComp.isPlaying && !noPower)
            {
                LightObject.intensity = 0f;
                AnimationComp.Play(NoPowerAnim);
                noPower = true;
            }
        }
    }
Exemple #30
0
    void Update()
    {
        if (inputManager && inputManager.HasInputs())
        {
            GrabButton   = inputManager.GetInput("Pickup");
            ThrowButton  = inputManager.GetInput("Throw");
            rotateObject = inputManager.GetInput("Fire");
        }

        gameManager.isHeld = objectHeld != false;
        interact.isHeld    = objectHeld != false;

        if (gameManager.isPaused)
        {
            return;
        }

        if (objectRaycast && !antiSpam)
        {
            if (Input.GetKeyDown(GrabButton) && !isPressed)
            {
                isPressed  = true;
                GrabObject = !GrabObject;
            }
            else if (isPressed)
            {
                isPressed = false;
            }
        }

        if (GrabObject)
        {
            if (!isObjectHeld)
            {
                TryPickObject();
            }
            else
            {
                HoldObject();
            }
        }
        else if (isObjectHeld)
        {
            DropObject();
        }

        if (Input.GetKey(ThrowButton))
        {
            if (objectHeld)
            {
                throwPressed = true;
                isObjectHeld = false;
                ThrowObject();
            }
        }
        else if (throwPressed)
        {
            pfunc.zoomEnabled = true;
            throwPressed      = false;
        }

        Ray        playerAim = playerCam.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
        RaycastHit hit;

        float rotationInputX = 0.0f;
        float rotationInputY = 0.0f;

        float x = Input.GetAxis("Mouse X");
        float y = Input.GetAxis("Mouse Y");

        if (Mathf.Abs(x) > rotationDeadzone)
        {
            rotationInputX = -(x * rotateSpeed);
        }

        if (Mathf.Abs(y) > rotationDeadzone)
        {
            rotationInputY = (y * rotateSpeed);
        }

        if (Physics.Raycast(playerAim, out hit, PickupRange, CullLayers))
        {
            if (hit.collider.gameObject.layer == LayerMask.NameToLayer(GrabLayerName))
            {
                if (hit.collider.tag == GrabTag)
                {
                    objectRaycast       = hit.collider.gameObject;
                    gameManager.canGrab = true;
                }
            }
            else
            {
                if (!isObjectHeld)
                {
                    objectRaycast       = null;
                    gameManager.canGrab = false;
                }
            }

            if (objectHeld)
            {
                if (Input.GetKey(rotateObject) && enableObjectRotation)
                {
                    gameManager.LockPlayerControls(false, false, false);
                    objectHeld.GetComponent <Rigidbody>().freezeRotation = true;
                    objectHeld.transform.Rotate(playerCam.transform.up, rotationInputX, Space.World);
                    objectHeld.transform.Rotate(playerCam.transform.right, rotationInputY, Space.World);
                }
                else
                {
                    gameManager.LockPlayerControls(true, false, false);
                }

                if (enableObjectZooming)
                {
                    distance = Mathf.Clamp(distance, minDistanceZoom, maxDistanceZoom);
                    float mw = Input.GetAxis("Mouse ScrollWheel") * objectZoomSpeed;
                    if (mw > 0 && distance < maxDistanceZoom)
                    {
                        distance += mw;
                    }
                    else if (mw < 0 && distance > minDistanceZoom)
                    {
                        distance += mw;
                    }
                }
            }
        }
        else
        {
            if (!isObjectHeld)
            {
                objectRaycast       = null;
                gameManager.canGrab = false;
            }
        }
    }