- Home /
Not getting Score
Hi guys im using this script to show my player score but it seems my player score is not showing. Deaths is showing But score and kills is not.Here's my script
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Character : MonoBehaviour {
public Transform FirstPerson;
public WeaponManager FirstpersonCont;
public Transform ThirdPerson;
public NetworkManager.Player MyPlayer;
public Vector3 CurPos;
public Quaternion CurRot;
public GameObject RagDoll;
public List<ThirdPersonGuns> Guns = new List<ThirdPersonGuns>();
public NetworkManager.Player LastShootBy;
public string LastShootByName;
// Use this for initialization
void Start () {
MyPlayer.Manager = this;
MyPlayer = NetworkManager.GetPlayer (networkView.owner);
FirstPerson.gameObject.SetActive (false);
ThirdPerson.gameObject.SetActive (false);
DontDestroyOnLoad (gameObject);
}
// Update is called once per frame
void Update () {
}
[RPC]
public void FindHitter(string name)
{
LastShootBy = NetworkManager.GetPlayer(name);
LastShootByName = name;
}
[RPC]
public void GetKill()
{
RankManager.Inst.Exp += 100;
MyPlayer.Score += 100;
MyPlayer.Kills++;
}
[RPC]
void Server_TakeDamage (float Damage)
{
networkView.RPC ("Client_TakeDamage", RPCMode.Server, Damage);
}
[RPC]
void Client_TakeDamage (float Damage)
{
MyPlayer.Health -= Damage;
Debug.Log (MyPlayer.Health);
if (MyPlayer.Health <= 0)
{
//networkView.RPC("Die",RPCMode.All);
Die();
MyPlayer.IsAlive = false;
MyPlayer.Health = 0;
Instantiate(RagDoll,ThirdPerson.position,ThirdPerson.rotation);
}
}
[RPC]
void Spawn()
{
MyPlayer.Health = 100;
MyPlayer.IsAlive = true;
if (networkView.isMine)
{
FirstPerson.gameObject.SetActive (true);
ThirdPerson.gameObject.SetActive (false);
}
else
{
FirstPerson.gameObject.SetActive (false);
ThirdPerson.gameObject.SetActive (true);
}
}
[RPC]
public void Die()
{
MyPlayer.IsAlive = false;
MyPlayer.Deaths++;
FirstPerson.gameObject.SetActive (false);
ThirdPerson.gameObject.SetActive (false);
if (LastShootBy != null)
LastShootBy.Manager.networkView.RPC("GetKill",LastShootBy.OnlinePlayer);
}
void OnSerializeNetworkView(BitStream stream,NetworkMessageInfo info)
{
if (stream.isWriting)
{
CurPos = FirstPerson.position;
CurRot = FirstPerson.rotation;
stream.Serialize(ref CurPos);
stream.Serialize(ref CurRot);
char Ani = (char)GetComponent<NetworkAnimsStates>().CurrentAnim;
stream.Serialize (ref Ani);
}
else
{
stream.Serialize(ref CurPos);
stream.Serialize(ref CurRot);
ThirdPerson.position = CurPos;
ThirdPerson.rotation = CurRot;
char Ani = (char)0;
stream.Serialize(ref Ani);
GetComponent<NetworkAnimsStates>().CurrentAnim = (NetworkAnimsStates.Animations)Ani;
}
}
public void Server_GetGun(string name)
{
networkView.RPC ("Client_GetGun", RPCMode.All, name);
Debug.Log (name);
}
[RPC]
public void Client_GetGun(string name)
{
foreach (ThirdPersonGuns tpg in Guns)
{
if(tpg.Name == name)
{
tpg.Obj.SetActive(true);
Debug.Log (tpg + "Done");
}
else
{
tpg.Obj.SetActive (false);
Debug.Log (tpg + "Not Done");
}
}
}
[System.Serializable]
public class ThirdPersonGuns
{
public string Name;
public GameObject Obj;
}
}
You do seem to be capturing your score in the code you shared. on line 44
public void Get$$anonymous$$ill()
{
...
$$anonymous$$yPlayer.Score += 100;
...
}
However after that (at least not in the code you shared) you don't seem to call upon the score anywhere else to display it.
opps sorry
public List<string> WeaponNames = new List<string>();
public List<string> SightNames = new List <string> ();
public int CurWeapon;
public int LastWeapon;
public static GUI$$anonymous$$anager Instance;
public bool ShowBoard;
// Use this for initialization
void Start () {
Instance = this;
foreach (Sight s in Network$$anonymous$$anager.Instance.$$anonymous$$yPlayer.$$anonymous$$anager.FirstpersonCont.Weapons[0].Sights.ToArray())
{
SightNames.Add (s.Name);
}
}
// Update is called once per frame
void Update () {
if (LastWeapon != CurWeapon)
{
ChangedGun();
}
//if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.Tab))
// ShowBoard = !ShowBoard;
if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.Tab))
ShowBoard = true;
else
ShowBoard = false;
}
void OnGUI()
{
if (Network$$anonymous$$anager.Instance.$$anonymous$$atchStarted && !Network$$anonymous$$anager.Instance.$$anonymous$$yPlayer.IsAlive)
{
CurWeapon = GUILayout.SelectionGrid (CurWeapon, WeaponNames.ToArray(), 4);
Network$$anonymous$$anager.Instance.$$anonymous$$yPlayer.$$anonymous$$anager.FirstpersonCont.Weapons[CurWeapon].CurSight = GUILayout.SelectionGrid(Network$$anonymous$$anager.Instance.$$anonymous$$yPlayer.$$anonymous$$anager.FirstpersonCont.Weapons[CurWeapon].CurSight,SightNames.ToArray(), 4);
}
if (ShowBoard && Network$$anonymous$$anager.Instance.$$anonymous$$atchStarted)
{
GUILayout.BeginArea(new Rect(Screen.width/4,Screen.height/4,(Screen.width) - (Screen.width/2),(Screen.height) - (Screen.height/2)),GUIContent.none,"box");
foreach (Network$$anonymous$$anager.Player pl in Network$$anonymous$$anager.Instance.PlayerList)
{
GUILayout.BeginHorizontal();
GUILayout.Label(pl.PlayerName);
GUILayout.Label(pl.Score.ToString());
GUILayout.Label(pl.$$anonymous$$ills.ToString());
GUILayout.Label(pl.Deaths.ToString());
GUILayout.EndHorizontal();
}
GUILayout.EndArea();
}
}
void ChangedGun()
{
SightNames.Clear ();
LastWeapon = CurWeapon;
foreach (Sight s in Network$$anonymous$$anager.Instance.$$anonymous$$yPlayer.$$anonymous$$anager.FirstpersonCont.Weapons[CurWeapon].Sights.ToArray())
{
SightNames.Add (s.Name);
}
}
Code looks good and works in regards to the GUI you're looking to create.
Did you check if the values Score and $$anonymous$$ill are actually stored? By calling them up via the Debug.Log?
It think they're being called but just not being stored
Your answer
![](https://koobas.hobune.stream/wayback/20220613153707im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiplying a string 1 Answer
Input string was not in the correct format 1 Answer
Please help get my code to work...compiler errors 2 Answers