Exemple #1
0
    // Update is called once per frame
    protected virtual void FixedUpdate()
    {
        var isPaused = SceneManagerScript.CheckPause();

        if (!isPaused)
        {
            var moveHorizontal = Input.GetAxis("Horizontal");
            var moveVertical   = Input.GetAxis("Vertical");

            var movement = new Vector2(moveHorizontal, moveVertical);

            //_rigidBody.MovePosition(movement);

            _rigidBody.AddForce(movement * Speed);
        }
    }
    // Update is called once per frame
    protected override void FixedUpdate()
    {
        var isPaused = SceneManagerScript.CheckPause();

        ReturnEnableCheck();

        if (_rayFiring && _fireCounter < 2)
        {
            _fireCounter++;
        }
        else if (_rayFiring && _fireCounter >= 2)
        {
            SwitchBeam(false);
            _rayFiring   = false;
            _fireCounter = 0;
        }

        CheckGround();

        if (!isPaused)
        {
            var moveHorizontal = Input.GetAxis("Horizontal");
            //Debug.Log($"Last Horizontal: {moveHorizontal}");
            var debugMessage = string.Empty;

            if (moveHorizontal > 0 && !FacingRight)
            {
                FacingRight = true;
                _cureRayRight.SetActive(true);
                _cureRayLeft.SetActive(false);
            }
            else if (moveHorizontal < 0 && FacingRight)
            {
                FacingRight = false;
                _cureRayLeft.SetActive(true);
                _cureRayRight.SetActive(false);
            }

            //if (FacingRight)
            //{
            //    debugMessage = "I am facing Right!";
            //}
            //else
            //{
            //    debugMessage = "I am Facing Left!";
            //}

            //Debug.Log(debugMessage);

            var moveVertical = 0;// Input.GetAxis("Vertical");

            //var movementSpeed = Mathf.Lerp(_rigidBody.velocity.x, Input.GetAxis("Horizontal") * Speed * Time.deltaTime, Time.deltaTime * 10); //new Vector2(moveHorizontal, moveVertical);
            var movement = new Vector2(moveHorizontal, moveVertical);

            if (Input.GetKeyDown(KeyCode.Space) && _isGrounded)
            {
                _rigidBody.AddForce(new Vector2(0, 15), ForceMode2D.Impulse);
                _isGrounded = false;
            }

            if (Input.GetKeyDown(KeyCode.H) && _fireCounter == 0)
            {
                Debug.Log("Shoot the 'Laser'!");

                SwitchBeam(true);

                _rayFiring = true;

                RaycastHit2D cureStrike = new RaycastHit2D();

                var thisVector = new Vector2(_rigidBody.transform.position.x, _rigidBody.transform.position.y - .13f);

                if (FacingRight)
                {
                    cureStrike = Physics2D.Raycast(thisVector, Vector2.right, 1);
                }
                else
                {
                    cureStrike = Physics2D.Raycast(thisVector, Vector2.left, 1);
                }

                //int layerMask = ~(1 << 8);

                if (cureStrike.collider == null)
                {
                    Debug.Log($"We hit nothing, Lebowski!");
                }
                else
                {
                    Debug.Log($"We hit {cureStrike.collider.gameObject.name}");
                    var script = cureStrike.collider.gameObject.GetComponent <DoomCatController>();
                    Debug.Log(script);
                    script.UpdateCurePoints();
                }
            }

            //_rigidBody.AddForce(new Vector2(movementSpeed, _rigidBody.velocity.x));

            //_rigidBody.velocity = new Vector2(movementSpeed, _rigidBody.velocity.x);

            _rigidBody.AddForce(movement * Speed);
            //_rigidBody.MovePosition(movement);
        }
    }