Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Codigo del Objeto "Cliente":
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Networking;
- public class PlayerObejct : NetworkBehaviour {
- public GameObject playerPrefab;
- GameObject myPlayerUnit;
- [SyncVar(hook = "OnPlayerNameChanged")]
- public string playerName = "Anonymous";
- public Vector3 spawnPosition;
- public Image hpBar;
- // Use this for initialization
- void Start () {
- if (!isLocalPlayer)
- return;
- CmdCheckPlayer();
- }
- // Update is called once per frame
- void Update () {
- if (!isLocalPlayer)
- return;
- if (gameObject.name != playerName)
- {
- gameObject.name = playerName;
- }
- }
- void OnPlayerNameChanged(string newName)
- {
- gameObject.name = newName;
- playerName = newName;
- }
- [Command]
- void CmdSpawnMyUnit(Vector3 t)
- {
- GameObject go = Instantiate(playerPrefab);
- myPlayerUnit = go;
- myPlayerUnit.transform.position = t;
- myPlayerUnit.GetComponent<PlayerUnit>().creatorName=gameObject.name;
- NetworkServer.SpawnWithClientAuthority(go, connectionToClient);
- }
- [Command]
- void CmdChangePlayerName(string n)
- {
- playerName = n;
- }
- [Command]
- void CmdCheckPlayer()
- {
- if (!GameObject.Find("Player1"))
- {
- CmdChangePlayerName("Player1");
- spawnPosition = new Vector3(4.27f, 0, -4.51f);
- hpBar = GameObject.Find("Player1Bar").GetComponent<Image>();
- }
- else
- {
- CmdChangePlayerName("Player2");
- spawnPosition = new Vector3(-4.07f, 0, -4.51f);
- hpBar = GameObject.Find("Player2Bar").GetComponent<Image>();
- }
- CmdSpawnMyUnit(spawnPosition);
- }
- }
- Codigo de la Instancia del "Cliente":
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Networking;
- public class PlayerUnit : NetworkBehaviour {
- public string creatorName;
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- if (!hasAuthority)
- {
- return;
- }
- if (Input.GetKeyDown(KeyCode.Space))
- {
- }
- }
- [Command]
- void CmdDealDmg()
- {
- // Funcion para hacer daño al otro;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement