Untitled

mail@pastecode.io avatar
unknown
csharp
2 years ago
1.0 kB
2
Indexable
Never
    void Inputs()
    {
        if (!isHurted)
        {
            inputDirection = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
            inputDirection.Normalize();
        }

        if(Input.GetMouseButtonDown(0))
        {
            Vector3 targetDirection = (mousePosition - transform.position).normalized;

            float range = 0.5f; // Default range when have no weapon.

            if(weapon != null)
            {
                range = weapon.range;
            }
              
            RaycastHit2D hit = Physics2D.Raycast(new Vector2(transform.position.x, transform.position.y + 0.5f), targetDirection, range, enemyLayer);

            if(hit)
            {
                Debug.Log("Range was: "+ range + "and we hitted: " + hit.collider.name);
            }
        }
    }
    void UpdateMouse()
    {
        mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        mousePosition.z = 0;
    }