protected virtual void Update()
    {
        var diff = player.transform.position - transform.position;

        if (diff.sqrMagnitude < interactDist * interactDist && looking /*&& Vector3.Dot( -diff.normalized,
                                                                        * ( cam.gameObject.transform.forward + Vector3.up * 0.2f ).normalized ) > interactTolerance*/)
        {
            // if( looking )
            {
                pickupText.gameObject.SetActive(true);
                pickupText.transform.position = transform.position + Vector3.up * heightOffset;

                if (SpiffyInput.CheckAxis("Interact"))
                {
                    Interact();
                    audSrc.PlayOneShot(interactSound);
                }
            }
        }
        else
        {
            UnInteract();
        }

        looking = false;
    }
 void Update()
 {
     if (SpiffyInput.CheckAxis("Inventory"))
     {
         ToggleOpen(!open);
     }
 }
Esempio n. 3
0
 void Update()
 {
     if (SpiffyInput.CheckAxis("Menu", true) /* || Input.GetKeyDown( KeyCode.Escape )*/)
     {
         ToggleOpen(!open);
     }
 }
    void Update()
    {
        var diff = player.transform.position - transform.position;

        if (diff.sqrMagnitude < interactDist * interactDist)
        {
            pickupText.gameObject.SetActive(true);
            pickupText.transform.position = transform.position + Vector3.up * heightOffset;

            if (SpiffyInput.CheckAxis(interactAxis))
            {
                if (prefAdd.Length > 0)
                {
                    PlayerPrefs.SetInt(prefAdd, 1);
                }

                SceneManager.LoadScene(targetScene);
            }

            transform.Rotate(Vector3.up, spinSpd * Time.deltaTime);
            transform.position = origPos + Vector3.up * upHeight;
        }
        else
        {
            pickupText.gameObject.SetActive(false);
            transform.position = origPos;
        }
    }
Esempio n. 5
0
    void Update()
    {
        refire.Update(Time.deltaTime);
        if (SpiffyInput.CheckAxis("Fire1") && canFire && refire.IsDone())
        {
            var        knockbackDir = -cam.transform.forward;
            RaycastHit hit;
            if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, 999.0f, shotMask))
            {
                playerMoveScr.ApplyForceMove(knockbackDir.normalized * Mathf.Min(
                                                 knockbackForce * (2.0f / hit.distance), maxForce));

                canFire = false;
                refire.Reset();

                var curPellets = pelletCount.Rand();
                for (int i = 0; i < curPellets; ++i)
                {
                    SpawnTrail(hit.point + new Vector3(
                                   Random.Range(0.0f, 1.0f),
                                   Random.Range(0.0f, 1.0f),
                                   Random.Range(0.0f, 1.0f)) *
                               Mathf.Max(minSpread, pelletSpread * Mathf.Sqrt(hit.distance)));
                }

                audSrc.PlayOneShot(shootAud);
            }
        }

        if (charCtrl.isGrounded)
        {
            if (!canFire)
            {
                audSrc.PlayOneShot(reloadAud);
            }
            canFire = true;
        }
    }
    void Update()
    {
        // if( SpiffyInput.CheckAxis( "Menu" ) )
        // {
        //  Cursor.lockState = CursorLockMode.None;
        //  Cursor.visible = true;
        //  escape = true;
        // }
        if (SpiffyInput.CheckAxis("Fire1") && !playerInv.IsOpen() && !PauseMenu.IsOpen())
        {
            Cursor.lockState = CursorLockMode.Locked;
            Cursor.visible   = false;
            escape           = false;
        }

        if (!escape && !playerInv.IsOpen() && !PauseMenu.IsOpen())
        {
            var aim = new Vector2(Input.GetAxis("Mouse X"),
                                  Input.GetAxis("Mouse Y"));

            // aim.y = aim.y * rotationSpeed * sensitivity * Time.deltaTime;
            aim = aim * rotationSpeed * sensitivity * Time.deltaTime;
            if (aim.y > maxAimMove)
            {
                aim.y = maxAimMove;
            }
            if (aim.y < -maxAimMove)
            {
                aim.y = -maxAimMove;
            }

            var tempAng = transform.eulerAngles;
            tempAng.x = tempAng.x - aim.y;
            if (tempAng.x > 90.0f - verticalCutoff && tempAng.x < 180.0f)
            {
                tempAng.x = 90.0f - verticalCutoff;
            }
            if (tempAng.x < 270.0f + verticalCutoff && tempAng.x > 180.0f)
            {
                tempAng.x = 270.0f + verticalCutoff;
            }
            tempAng.y             = tempAng.y + aim.x /* * rotationSpeed * Time.deltaTime*/;
            transform.eulerAngles = tempAng;

            // distToPlayer -= Input.GetAxis( "Mouse ScrollWheel" ) *
            //  scrollSpeed * Time.deltaTime;

            // distToPlayer = Mathf.Max( minDistToPlayer,distToPlayer );
            // distToPlayer = Mathf.Min( maxDistToPlayer,distToPlayer );
        }

        transform.position = player.transform.position +
                             transform.right * offset.x +
                             transform.up * offset.y +
                             transform.forward * offset.z;
        transform.position -= transform.forward * distToPlayer;

        var        clipRay = new Ray(player.transform.position, transform.position - player.transform.position);
        RaycastHit clipHit;

        if (Physics.Raycast(clipRay, out clipHit, distToPlayer, worldMask))
        {
            transform.position = clipHit.point + clipHit.normal * cam.nearClipPlane * 1.5f;
        }

        var        interactRay = new Ray(transform.position + transform.forward * distToPlayer / 2.0f, transform.forward);
        RaycastHit interactHit;

        if (Physics.Raycast(interactRay, out interactHit, 100.0f, itemMask))
        {
            interactHit.transform.GetComponent <InteractiveBase>()?.Look();
        }
    }