Whether you have an Android or Apple device, download Droidcam. You will then need to download their client to your computer.
Once downloaded, run it on both the phone and computer.
You can then connect via USB or WiFi, and your phone will now act as a camera source on your PC. It is recommended to keep your phone on charge whilst using it as a webcam as it can heavily drain your phone’s battery.