using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class Health : NetworkBehaviour
{
public const int maxHealth = 100;
//需要同步的变化
[SyncVar(hook ="OnChangeHealth")]
public int currentHealth = maxHealth;
//血条
public RectTransform healthbar;
public void TakeDamage(int amount)
{
//为了保持变量一致,作为服务端时才处理
if (!isServer)
return;
currentHealth -= amount;
if(currentHealth
关注
打赏
Unity多人游戏简单实例(一)同步变量
立即登录/注册


微信扫码登录