-
Notifications
You must be signed in to change notification settings - Fork 0
/
spawnPrefab.cs
42 lines (38 loc) · 1.14 KB
/
spawnPrefab.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class spawnPrefab : NetworkBehaviour
{
public GameObject SpawnObj;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Alpha1))
{
if (isServer)
{
CmdSpawnSwordServer();
}
else
{
CmdSpawnSwordClient();
}
}
}
[Command]
void CmdSpawnSwordServer()
{
var Aiagent = (GameObject)GameObject.Instantiate(SpawnObj, SpawnObj.transform.position, SpawnObj.transform.rotation);
NetworkServer.Spawn(Aiagent);
}
[Command]
void CmdSpawnSwordClient()
{
GameObject troop = Instantiate(SpawnObj, transform.position, Quaternion.identity) as GameObject;
troop.transform.tag = tag;
troop.transform.FindChild("Hips").tag = tag;
troop.transform.FindChild("Paladin_J_Nordstrom_Sword").tag = "SwordE";
NetworkServer.SpawnWithClientAuthority(troop, gameObject);
}
}