Finding the player that walked into a ray?

Hello, I’m trying to figure out how to set the player that walked into a ray as variable, and then make a prefab of that player so I can destroy, set it’s camera to whatever I want EG: Cannon, helicopter, ect then use the prefab to respawn it. The reason I want to find the player and create a prefab instead of just doing that before hand is I want to be able to do multiplayer down the road without having to re-do a bunch of stuff.

To recap I need to know how to get a player using raycast from another object such as a cannon, turn that player into a variable inside the cannon script and turn it into a prefab so I can respawn it later.

I’m sure this is fairly simple but thanks for your help!

While the detection is easy with raycast’s out parameter. But the creation of prefab at runtime is not possible. Unity isn’t built that way. You need to create prefabs before hand and just switch them at runtime with some kind of manager script.