For various occasions, I need to determine if the target is enemy or ally. For example a bullet hit, a ray cast, etc. But I don’t want to use a layer for each player.
How can I achieve this?
I was thinking of a unique ID for each player, like with InstanceID, and store it on the bullet and check it upon impact.
Give the bullet a simple script that holds things like damage, speed etc. You will probably need those things anyway to make the bullet move when firing it, so you might as well add those to a script on it. the script may also hold things like “user”, which would reference the gameobject that fired it, or simply a player number or something else to differentiate who fired it. Upon impact, you can then check this value against the impact recipient (if it’s not a wall or similar, of course). This also allows you to create on-screen death messages like “Player 1 killed Player 2”.