I just started like a week using unity, and I’m learning some C# too (Brackeys Youtube tutorials).
Well I made a scene with a player prefab, 2 spawn points, a _NetworkManager and some other scripts too… but I don’t know how to set the 2 teams(I only have the tags for the 2 teams ). And the capture zone… for now it would be a box or sphere without the meshes, and I think some kind of script that detects the number of players in the zone, and then a little HUD symbol that turns blue or red depending on the number of players of each team in the zone.
My objective doing this is to learn, so I don’t want to use any premade assets please.
I have a last question, if I do not win any money doing a “game”, can I use copyrighted content?
It’s still not legal, though it’s unlikely that the copyright owner will notice you, or care if they do. If your game gets any sort of public notice, though, they’ll send you a cease & desist to kill it. Basically, using copyright assets is banking on your game never catching on. Probably alright for learning-experiment type games, but nothing else.
If you’re using tags, then setting the teams when you spawn players should be pretty straightforward:
GameObject spawned = Instantiate(prefab) as GameObject;
spawned.tag = "RedTeam";
You can do this with a trigger collider. The main issue would be that trigger colliders don’t actually maintain a list of objects they’re overlapping (at least not one you can access), they only send messages when colliders enter and leave. So you’ll have to maintain that list yourself.
I recommend the List class. It’s basically an array that you can add and remove items from freely, and it’s a generic class, meaning that it knows what type of object to expect, and you don’t have to cast things. You’ll have to add System.Collections.Generic to your “using” directives at the top of your script. Then:
List<PlayerClass> overlappingPlayers;
void OnTriggerEnter(Collider c) {
if (overlappingPlayers == null) overlappingPlayers = new List<PlayerClass>(); // a list starts off as 'null', so it must be initialized. This could be done in Awake or Start if you prefer
PlayerClass thisPlayer = c.GetComponent<PlayerClass>();
if (thisPlayer != null) { //is the thing that entered the trigger actually a player?
overlappingPlayers.Add(thisPlayer);
}
}
void OnTriggerExit(Collider c) {
PlayerClass thisPlayer = c.GetComponent<PlayerClass>();
if (thisPlayer != null) {
overlappingPlayers.Remove(thisPlayer);
}
}
So now you can use overlappingPlayers.Count to see how many players are in that zone, and if needed you can loop through overlappingPlayers using foreach. I will leave detecting the teams of the players based on tags as an exercise to the reader for now.
Thanks a lot for you good answer, now I have to do something, but when I’ll be back I’m going to use this and see if I can get this working.
Thanks again.
For the teams, I’m using a “Network Manager” script, and 2 spawn points “Network Start Position” Where I should put the team Code? I should create a new script?
For the Capture point, I don’t know how to do this, but I think creating an empty Game object, and adding a Collider, then checking the box “is trigger”, maybe?