Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        Vector2 mouseScreenPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        // get direction you want to point at
        Vector2 direction = (mouseScreenPosition - (Vector2)transform.position).normalized;

        // set vector of transform directly
        transform.up = Vector2.Lerp(transform.up, direction, 10f * Time.deltaTime);
        if (Input.GetMouseButtonDown(0))
        {
            torchToggled = !torchToggled;
        }
        if (torchToggled)
        {
            startDrag = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            torch.pointLightInnerRadius = Mathf.Lerp(torch.pointLightInnerRadius, 20f, torchSpeed * Time.deltaTime);
            torch.pointLightOuterRadius = Mathf.Lerp(torch.pointLightOuterRadius, 40f, torchSpeed * Time.deltaTime);
            torch.pointLightInnerAngle  = Mathf.Lerp(torch.pointLightInnerAngle, 9f, torchSpeed * Time.deltaTime);
            torch.pointLightOuterAngle  = Mathf.Lerp(torch.pointLightOuterAngle, torchOuterAngle, torchSpeed * Time.deltaTime);
        }
        else
        {
            torch.pointLightInnerRadius = Mathf.Lerp(torch.pointLightInnerRadius, torchInnerRadius, torchSpeed * Time.deltaTime);
            torch.pointLightOuterRadius = Mathf.Lerp(torch.pointLightOuterRadius, torchOuterRadius, torchSpeed * Time.deltaTime);
            torch.pointLightInnerAngle  = Mathf.Lerp(torch.pointLightInnerAngle, torchInnerAngle, torchSpeed * Time.deltaTime);
            torch.pointLightOuterAngle  = Mathf.Lerp(torch.pointLightOuterAngle, torchOuterAngle, torchSpeed * Time.deltaTime);
        }

        if (Input.GetKey(KeyCode.LeftShift))
        {
            Vector2 releasePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            currentSpeed = Vector2.Distance(startDrag, releasePos) * forceStrength > maxStrength
                ? maxStrength
                : Vector2.Distance(startDrag, releasePos) * forceStrength;
            Vector2 scaleChange = new Vector2(currentSpeed / 10, currentSpeed / 10);
            powerUpSpriteMask.localScale = scaleChange;
        }
        if (Input.GetKey(KeyCode.LeftShift))
        {
            Vector2 releasePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            float   angle      = Helpers.AngleBetweenVector2(transform.position, releasePos);
            rb.AddForce(Helpers.AngleToForce(angle, forceStrength));
            powerUpSpriteMask.localScale = new Vector2(0, 0);
        }


        if (Input.GetMouseButtonDown(1))
        {
            gunfire.enabled = true;
            lastShotFires   = Time.time;
            Shoot(transform.position, direction);
        }
        if (Input.GetMouseButtonUp(0))
        {
            torchCollider.GenerateCollider();
        }

        isMoving = Mathf.Abs(rb.velocity.x) != 0 || Mathf.Abs(rb.velocity.y) != 0;


        if (rb.velocity.magnitude > 0.1f)
        {
            rb.velocity = rb.velocity * 0.96f;

            if (!dashing)
            {
                playerAnimator.SetBool("walking", true);
            }
        }
        else
        {
            playerAnimator.SetBool("walking", false);
            rb.velocity = new Vector3(0, 0, 0);
        }
        if (lastShotFires + gunfireDuration < Time.time)
        {
            gunfire.enabled = false;
        }
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        Vector2 mouseScreenPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        // get direction you want to point at
        Vector2 direction = (mouseScreenPosition - (Vector2)transform.position).normalized;

        // set vector of transform directly
        transform.up = Vector2.Lerp(transform.up, direction, 10f * Time.deltaTime);

        if (Input.GetMouseButtonDown(0))
        {
            torchToggled = !torchToggled;
        }
        if (torchToggled)
        {
            startDrag = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            torch.pointLightInnerRadius = Mathf.Lerp(torch.pointLightInnerRadius, 20f, torchSpeed * Time.deltaTime);
            torch.pointLightOuterRadius = Mathf.Lerp(torch.pointLightOuterRadius, 40f, torchSpeed * Time.deltaTime);
            torch.pointLightInnerAngle  = Mathf.Lerp(torch.pointLightInnerAngle, 9f, torchSpeed * Time.deltaTime);
            torch.pointLightOuterAngle  = Mathf.Lerp(torch.pointLightOuterAngle, 9f, torchSpeed * Time.deltaTime);
        }
        else
        {
            torch.pointLightInnerRadius = Mathf.Lerp(torch.pointLightInnerRadius, torchInnerRadius, torchSpeed * Time.deltaTime);
            torch.pointLightOuterRadius = Mathf.Lerp(torch.pointLightOuterRadius, torchOuterRadius, torchSpeed * Time.deltaTime);
            torch.pointLightInnerAngle  = Mathf.Lerp(torch.pointLightInnerAngle, torchInnerAngle, torchSpeed * Time.deltaTime);
            torch.pointLightOuterAngle  = Mathf.Lerp(torch.pointLightOuterAngle, torchOuterAngle, torchSpeed * Time.deltaTime);
        }

        if (Input.GetKey(KeyCode.LeftShift))
        {
            Vector2 releasePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            currentSpeed = Vector2.Distance(startDrag, releasePos) * forceStrength > maxStrength
                ? maxStrength
                : Vector2.Distance(startDrag, releasePos) * forceStrength;
            Vector2 scaleChange = new Vector2(currentSpeed / 10, currentSpeed / 10);
            powerUpSpriteMask.localScale = scaleChange;
        }
        if (Input.GetKey(KeyCode.LeftShift))
        {
            Vector2 releasePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            float   angle      = Helpers.AngleBetweenVector2(transform.position, releasePos);
            rb.AddForce(Helpers.AngleToForce(angle, forceStrength));
            gm.incrementScore();
            powerUpSpriteMask.localScale = new Vector2(0, 0);
        }

        if (Input.GetKey("w"))
        {
            rb.AddForce(Vector2.up * 5);
        }

        if (Input.GetKey("a"))
        {
            rb.AddForce(Vector2.left * 5);
        }

        if (Input.GetKey("d"))
        {
            rb.AddForce(Vector2.right * 5);
        }

        if (Input.GetKey("s"))
        {
            rb.AddForce(Vector2.down * 5);
        }

        if (Input.GetMouseButtonUp(0))
        {
            torchCollider.GenerateCollider();
        }
        rb.velocity = rb.velocity * 0.99f;
    }