@Rilawer

Посмотрите этот код, скажите что можно в нём исправить, делал подбор оружия в 2д игре?

public bool hold;
    public float distanse = 5f;
        RaycastHit2D hit;
    public Transform holdPoint;
    public float trow = 2f;
    EdgeCollider2D ed;
    // Start is called before the first frame update
    void Start()
    {
       ed = GetComponent<EdgeCollider2D>();
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.Q))
        {
            if(!hold)
            {
                Physics2D.queriesStartInColliders = false;
                hit = Physics2D.Raycast(transform.position, Vector2.right * transform.localScale.x, distanse);
                if (hit.collider != null && hit.collider.tag == "weapon") 
                {
                    hold = true;
                }

            }
            else
            {
                hold = false;
                if(hit.collider.gameObject.GetComponent<Rigidbody2D>() != null)
                {
                    hit.collider.gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(transform.localScale.x, 1) * trow;
                }
            }
        }
        if(hold)
        {
            hit.collider.gameObject.transform.position = holdPoint.position;
        }
    }


Как его можно упростить?
  • Вопрос задан
  • 80 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы