void AddScore(Collider toon) { // step 1 : spawn effect when collide Instantiate(collectablesEffect, transform.position, transform.rotation); // step 2 : add score Debug.Log("Crashing into collectables.."); String name = toon.GetComponent <ProtoMove>().owner; // get the owner of the toon int j = 0; ProtoContrl ply = null; foreach (ProtoContrl p in plyrs) { Debug.Log(plyrs[j].pname + " " + name); if (plyrs[j].pname == name) // checking the name { ply = plyrs[j]; } j++; } ply.playerScore += score; // adding score to playerScore in ProtoContrl (total score stored there) Debug.Log(ply.pname + " new score : " + ply.playerScore); // step 3 : remove collectables from the game CmdDestroyGameObject(gameObject); }
public override void OnLobbyServerSceneLoadedForPlayer(NetworkManager manager, GameObject lobbyPlayer, GameObject gamePlayer) { LobbyPlayer lobPlayer = lobbyPlayer.GetComponent <LobbyPlayer>(); ProtoContrl locPlayer = gamePlayer.GetComponent <ProtoContrl>(); locPlayer.pname = lobPlayer.playerName; locPlayer.pcolor = lobPlayer.playerColor; }
void KillToons(Collider toon) { // step 1 : spawn effect when collided Instantiate(bombEffect, transform.position, transform.rotation); // step 2 : decrease score, destroy toons Debug.Log("Collectables is a bomb.."); String name = toon.GetComponent <ProtoMove>().owner; // get the owner of the toon int j = 0; ProtoContrl ply = null; foreach (ProtoContrl p in plyrs) { Debug.Log("Bomb collected by : " + plyrs[j].pname + " = " + name); if (plyrs[j].pname == name) { // checking the name ply = plyrs[j]; } j++; } // subtracting playerScore in ProtoContrl (total score stored there) ply.playerScore -= score; if (ply.playerScore < 0) { // we don't want any player got negative score, so we reset it back to zero ply.playerScore = 0; } Debug.Log(ply.pname + " new score : " + ply.playerScore); // decrease the health of the toon that collected that bomb toon.GetComponent <ProtoMove>().health -= score; Debug.Log("Toon new health: " + toon.GetComponent <ProtoMove>().health); // step 3 : remove collectables CmdDestroyGameObject(gameObject); }