Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        matchWaitTimer -= Time.deltaTime;
        if (matchWaitTimer < -600)
        {
            matchWaitTimer = 0f;
        }

        if (wait >= 0)
        {
            wait -= Time.deltaTime;
        }
        if (instantiatedMatch == null)
        {
            if (Input.GetKeyDown(KeyCode.Q))
            {
                if (matchWaitTimer <= 0)
                {
                    LightMatch();
                }
            }
        }
        else
        {
            if (Input.GetKeyDown(KeyCode.Q))
            {
                DropMatch();
            }
        }

        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out currentHit, Mathf.Infinity, LayerMask.GetMask("Object")))
        {
            IMoveableObject clickedObj = currentHit.collider.GetComponent <IMoveableObject>();
            if (clickedObj != null && wait < 0)
            {
                if (Input.GetMouseButton(0) && !clickedObj.IsHeld())
                {
                    clickedObj.OnClicked();
                    if (clickedObj.IsHeld())
                    {
                        clickedObjHeld = clickedObj;
                    }
                    wait = 2;
                }
                if (!clickedObj.IsHeld())
                {
                    clickedObj.OnMouseHover();
                }
            }
        }
        if (Input.GetMouseButtonDown(0) && clickedObjHeld != null && wait < 0)
        {
            clickedObjHeld.OnThrown();
            clickedObjHeld = null;
            wait           = 2;
        }
        if (!Input.GetMouseButton(1))
        {
            var mouseMovement = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));

            var mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude);

            Vector3 angleToChangeCamera;

            if ((mouseMovement.y * mouseSensitivityFactor) > 5)
            {
                angleToChangeCamera = new Vector3(5, 0f, 0f);
            }
            else if ((mouseMovement.y * mouseSensitivityFactor) < -5)
            {
                angleToChangeCamera = new Vector3(-5, 0f, 0f);
            }
            else
            {
                angleToChangeCamera = new Vector3(mouseMovement.y * mouseSensitivityFactor, 0f, 0f);
            }

            if (sceneCamera.eulerAngles.x > 355 && mouseMovement.y > 0)
            {
                sceneCamera.eulerAngles -= angleToChangeCamera;
            }
            else if (sceneCamera.eulerAngles.x >= 0 && sceneCamera.eulerAngles.x <= 30 && mouseMovement.y > 0)
            {
                sceneCamera.eulerAngles -= angleToChangeCamera;
            }
            else if (sceneCamera.eulerAngles.x >= 350 && sceneCamera.eulerAngles.x >= 0 && mouseMovement.y < 0)
            {
                sceneCamera.eulerAngles -= angleToChangeCamera;
            }
            else if (sceneCamera.eulerAngles.x < 25 && mouseMovement.y < 0)
            {
                sceneCamera.eulerAngles -= angleToChangeCamera;
            }

            transform.eulerAngles += new Vector3(0f, mouseMovement.x * mouseSensitivityFactor, 0f);
            if (!changedTransform)
            {
                if (mouseMovement != new Vector2(0f, 0f))
                {
                    changedTransform = true;
                }
                else
                {
                    changedTransform = false;
                }
            }
        }

        //updating animator variables to the bools within the character controller

        /*myAnimator.SetBool("IsWalking", isWalking);
         * myAnimator.SetBool("IsRunning", isRunning);
         * myAnimator.SetBool("IsJumping", isJumping);
         * myAnimator.SetBool("IsBack", isBack);
         * myAnimator.SetBool("IsRight", isRight);
         * myAnimator.SetBool("IsLeft", isLeft);*/
        GetComponent <Rigidbody>().angularVelocity = Vector3.zero;
        GetComponent <Rigidbody>().velocity        = Vector3.zero;
    }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        if (wait >= 0)
        {
            wait -= Time.deltaTime;
        }
        if (instantiatedMatch == null)
        {
            if (Input.GetKeyDown(KeyCode.Q))
            {
                LightMatch();
            }
        }
        else
        {
            if (Input.GetKeyDown(KeyCode.Q))
            {
                DropMatch();
            }
        }
        agentTarget.position = transform.position;
        agentTarget.position = RotateDestination(GetDirection(), agentTarget.position);
        agent.destination    = agentTarget.position;
        heldObject.position  = RotateDestination(new Vector3(-.5f, 1.5f, 2.5f), transform.position);
        heldObject.position  = RotateDestination(GetDirection(), heldObject.position);
        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out currentHit, Mathf.Infinity, LayerMask.GetMask("Default")))
        {
            IMoveableObject clickedObj = currentHit.collider.GetComponent <IMoveableObject>();
            if (clickedObj != null && wait < 0)
            {
                if (Input.GetMouseButton(0) && !clickedObj.IsHeld())
                {
                    clickedObj.OnClicked();
                    if (clickedObj.IsHeld())
                    {
                        clickedObjHeld = clickedObj;
                    }
                    wait = 2;
                }
                if (!clickedObj.IsHeld())
                {
                    clickedObj.OnMouseHover();
                }
            }
        }
        if (Input.GetMouseButtonDown(0) && clickedObjHeld != null && wait < 0)
        {
            clickedObjHeld.OnThrown();
            clickedObjHeld = null;
            wait           = 2;
        }
        if (!Input.GetMouseButton(1))
        {
            var mouseMovement = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));

            var mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude);

            sceneCamera.eulerAngles -= new Vector3(mouseMovement.y * mouseSensitivityFactor, 0f, 0f);
            transform.eulerAngles   += new Vector3(0f, mouseMovement.x * mouseSensitivityFactor, 0f);
            if (!changedTransform)
            {
                if (mouseMovement != new Vector2(0f, 0f))
                {
                    changedTransform = true;
                }
                else
                {
                    changedTransform = false;
                }
            }
        }

        //updating animator variables to the bools within the character controller
        myAnimator.SetBool("IsWalking", isWalking);
        myAnimator.SetBool("IsRunning", isRunning);
        myAnimator.SetBool("IsJumping", isJumping);
        GetComponent <Rigidbody>().angularVelocity = Vector3.zero;
        GetComponent <Rigidbody>().velocity        = Vector3.zero;
    }