28、击杀者的显示
在Player.cs中更新代码
using System;
using UnityEngine;
using UnityEngine.UI;
using Mirror;
public class Player : NetworkBehaviour
{
……
[HideInInspector] public string myName;
……
public override void OnStartLocalPlayer()
{
Camera.main.GetComponent<CamFollow>().target = transform;
GameManager.GetInstance().localPlayer = this;
}
public override void OnStartClient()
{
Team team = GameManager.GetInstance().teams[teamIndex];
for (int i = 0; i < renderers.Length; i++) // 遍历所有需要渲染的对象,即杆子和旗面
{
renderers[i].material = team.material;
}
// HP颜色的修改
myName = "Player";
label.text = myName;
hpImage.color = team.color;
}
……
[Server]
public void TankDamage(Bullet bullet)
{
health -= bullet.damage;
if (health <= 0)
{
// 当前玩家死亡
health = maxHealth;
RpcRespawn();
}
}
[ClientRpc]
protected virtual void RpcRespawn()
{
gameObject.SetActive(!gameObject.activeInHierarchy);
if (!isLocalPlayer) return;
bool isActive = gameObject.activeInHierarchy;
if (isActive)
{
// 重新放到出生点
}
else
{
camFollow.target = killedBy.transform;
GameManager.GetInstance().DisplayDeath();
}
}
……
}
在GameManager.cs中更新代码
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;
using Random = UnityEngine.Random;
public class G