35 lines
839 B
C#
35 lines
839 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Mirror;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class UnitSpawner : NetworkBehaviour, IPointerClickHandler
|
|
{
|
|
[SerializeField] private GameObject _unitPrefab;
|
|
[SerializeField] private Transform _unitSpawnPoint;
|
|
|
|
#region Server
|
|
|
|
[Command]
|
|
private void CmdSpawnUnit()
|
|
{
|
|
GameObject unitInstance = Instantiate(_unitPrefab, _unitSpawnPoint.position, _unitSpawnPoint.rotation);
|
|
|
|
NetworkServer.Spawn(unitInstance, connectionToClient);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Client
|
|
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
{
|
|
if (eventData.button != PointerEventData.InputButton.Left) return;
|
|
if (!isOwned) return;
|
|
CmdSpawnUnit();
|
|
}
|
|
}
|
|
|
|
#endregion |