Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Networking;
- public class Combat : NetworkBehaviour {
- public const int maxHealth = 100;
- public bool destroyOnDeath;
- public bool isEnemyNPC;
- public GameObject PlayerLastObject;
- public PlayerConfig playerLastHit;
- //dont forget to use function to generate exp //later calculate on server
- private int maxExp = 15;
- private int minExp = 10;
- [SyncVar]
- public int health = maxHealth;
- [SyncVar]
- public int LastPlayerNetworkID;
- [Command]
- public void CmdGiveExp()
- {
- if (PlayerLastObject != null && isServer)
- {
- playerLastHit = PlayerLastObject.GetComponent<PlayerConfig>();
- if (playerLastHit != null)
- {
- int amountToGive = Random.Range(minExp, maxExp);
- //ADJUST EXP ON CHARACTER THAT LAST HIT
- // int playerID = playerLastHit.GetComponent<NetworkConnection>().connectionId;
- // NetworkServer.SendToClient(playerID, sInt, );
- playerLastHit.recieveExp(amountToGive);
- }
- }
- }
- public void TakeDamage(int amount) {
- if(!isServer) { return; }
- health -= amount;
- if (health <= 0)
- {
- health = 0;
- if(isEnemyNPC) {
- //GIVE PLAYER EXP
- CmdGiveExp();
- }
- Debug.LogError("DEAD");
- if (destroyOnDeath)
- {
- Destroy(gameObject);
- }
- else
- {
- RpcRespawn();
- }
- }
- }
- [ClientRpc]
- void RpcRespawn() {
- if(isLocalPlayer) {
- transform.position = Vector3.zero;
- health = maxHealth;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment