Hello, I am going to make a soccer game where 2 players control different sides of the keyboard and try to get a soccerball into each others goal. When the ball rolls into the goal, I want the Player who scored to be given a point in a text box on the scene. How would I go about doing this?
Are you asking how to make the whole game?
Break it down into little pieces and get each piece working one by one.
1 Like
No, I have everything else working besides the point system, which I am trying to figure out how to do. I just need to know how to make the values of points increase when the soccerball rolls into the net.
you can create a class for this something like that
public class PointManager:MonoBehaviour
{
public int pointPlayer1;
public int pointPlayer2;
public Start()
{
pointPlayer1 = 0;
pointPlayer2 = 0;
}
public void AddPointToPlayer(int player, int amount)
{
switch(player)
{
case 1:
pointPlayer1 += amount;
break;
case 2 :
pointPlayer2+=amount;
break;
default:
break;
}
}
}
public class Goal:MonoBehaviour
{
[SerializeField] PointManager pointManager;
[SerializeFiled] private int playerOwner;
void OnTriggerEnter(Collider coll)
{
if(coll.gameobject.tag =="Ball")
{
pointManager.AddPointToPlayer(playerOwner,1);
}
}
}