Wybieranie aktywnego elementu 3D za pomocą myszy w Unity

Element 3D musi posiadać na sobie Collider.
Camera.main możemy cachować do zmiennej.

    GameObject activeObject;
    void Update()
        if (Input.GetMouseButtonDown(0))
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
                activeObject = hit.collider.gameObject;
Ask ChatGPT
Set ChatGPT API key
Find your Secret API key in your ChatGPT User settings and paste it here to connect ChatGPT with your Tutor LMS website.
Scroll to Top