简体   繁体   English

Unity 3d光子网络

[英]Unity 3d Photon Networking

the game i have created is a FPS game and it works with Photon Networking how the game works, when the player shoots another player on the network and kills him that player spawns a coin so a player can collect it and add a point to the score, 我创建的游戏是FPS游戏,它与Photon Networking协同工作,当玩家射击网络上的另一名玩家并杀死他时会产生硬币,从而杀死玩家,以便玩家收集硬币并为得分添加一个点,

BUT!!!! 但!!!!

The problem i am having when the player collects the coin it adds one point to all the people on the network 当玩家收集硬币时,我遇到的问题是它为网络上的所有人增加了1分

SO 所以

what i need help with is get the coin to give one point to the player that collected it and not to the whole network 我需要帮助的是拿硬币给收集它的玩家,而不是整个网络,给一分

MY CODE: this is to destroy the coin 我的密码:这是要摧毁硬币

    public float hitPoints = 100f;
    float currentHitPoints;
    public GameObject coin;

    [RPC]
    public void CoinDie(float amt) {
        currentHitPoints -= amt;

        if(currentHitPoints <= 0) {

            CoinDied();
        }
    }

    void CoinDied() {
        bl_SaveInfo.coinCount++;
        gu.coinCount++;
        CoinDestroy CD = GameObject.FindObjectOfType<CoinDestroy>();
        CD.KillCoin ();
       }


    }

this is the GUI that displays the points 这是显示点的GUI

using UnityEngine;
using System.Collections;

public class gu : MonoBehaviour {
    public static int coinCount = 0;
    float respawnTimer = 5;



    void OnGUI()
    {
        string coinText = "Total Coins: " + coinCount;

        GUI.Box (new Rect(Screen.width - 150, 40, 130, 30), coinText);

    }

    void Update(){
            respawnTimer -= Time.deltaTime;
    }
    public void Clear(){
        if (respawnTimer <= 0) {
            coinCount = 0;
            respawnTimer = 5;
        }
    }


    public void CoinCounter (){
            bl_SaveInfo.coinCount++;
            gu.coinCount++; 
        }



    void ClearScore(){
        coinCount = 0;
    }
}

You should make clear how and where coins count is stored. 您应该弄清楚硬币计数的方式和位置。 If you store it on network-synchronized game object representing player then count will increment on each RPC call for all instances of this player object over network leaving other players instances intact. 如果将其存储在表示玩家的网络同步游戏对象上,则此RPC对象在网络上的所有实例的每次RPC调用计数都会增加,而其他玩家实例则保持不变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM