Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Albert-han · Jul 10, 2014 at 09:57 AM · errorunexpected

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;
 }
 }
Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Zephire · Jul 10, 2014 at 10:08 AM 0
Share

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.

avatar image Albert-han · Jul 10, 2014 at 10:11 AM 0
Share

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);
         }
     }
avatar image Zephire · Jul 10, 2014 at 07:21 PM 0
Share

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?

avatar image Albert-han · Jul 10, 2014 at 10:47 PM 0
Share

Deaths is the only one thats stored

avatar image Albert-han · Jul 10, 2014 at 10:52 PM 0
Share

It think they're being called but just not being stored

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

Input string was not in the correct format 2 Answers

Parsing Error : Unexpected symbol 'end of file' 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges