Hi, so i have this code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class PlayerClass : NetworkBehaviour {
[SerializeField] private Camera playerCamera;
[SerializeField] private Camera spectatorCamera;
[SerializeField] private AudioClip trapClip;
[SerializeField] private AudioClip trapClipPlace;
[SerializeField] private GameObject cursor;
public int trapsCount = 0;
void Start()
{
if(ClassID == 2)
{
trapsCount = 1;
}
}
//ID 1 = Seeker | ID 2 = Hider
[SyncVar]public int ClassID;
[Command]
public void CmdSetPlayer()
{
spectatorCamera.gameObject.SetActive(false);
playerCamera.gameObject.SetActive(true);
}
[Command]
public void CmdSetSpectator()
{
spectatorCamera.gameObject.SetActive(true);
playerCamera.gameObject.SetActive(false);
}
[Command]
public void CmdRandomizeClass()
{
ClassID = Random.Range(1, 3);
}
//
//
//Trap Class
//
//
[Command]
public void CmdAssignAuthority(GameObject go)
{
//NetworkIdentity netID_ = go.GetComponent<NetworkIdentity>();
//netID_.AssignClientAuthority(connectionToClient);
go.GetComponent<NetworkIdentity>().AssignClientAuthority(connectionToClient);
}
[Command]
public void CmdRemoveAuthority(GameObject go)
{
NetworkIdentity netID_ = go.GetComponent<NetworkIdentity>();
netID_.RemoveClientAuthority(connectionToClient);
}
IEnumerator OnTriggerEnter(Collider other)
{
if (other.CompareTag("Trap"))
{
StartCoroutine(TrapPlayer(other.gameObject));
CmdAssignAuthority(other.gameObject);
CmdIsTrapped(true,other.gameObject);
Debug.Log(this.name + ": Assigning authority to: " + other.gameObject.name);
yield return new WaitForSeconds(5f);
CmdRemoveAuthority(other.gameObject);
Debug.Log(this.name + ": Removing authority from: " + other.gameObject.name);
}
}
[Command]
void CmdIsTrapped(bool result,GameObject go)
{
if (go.GetComponent<TrapClass>().isTrapped == false)
{
go.GetComponent<TrapClass>().isTrapped = result;
RpcPlaySFX(go);
}
}
[ClientRpc]
void RpcPlaySFX(GameObject go)
{
AudioSource.PlayClipAtPoint(trapClip,go.transform.position , 3f);
}
public IEnumerator TrapPlayer(GameObject other)
{
if (other.GetComponent<TrapClass>().isTrapped == false)
{
UnityStandardAssets.Characters.FirstPerson.FirstPersonController fps = this.GetComponent<UnityStandardAssets.Characters.FirstPerson.FirstPersonController>();
fps.m_WalkSpeed = 0;
fps.m_RunSpeed = 0;
fps.m_JumpSpeed = 0;
yield return new WaitForSeconds(10f);
fps.m_WalkSpeed = 5;
fps.m_RunSpeed = 10;
fps.m_JumpSpeed = 10;
}
}
[Command]
public void CmdPlaceTrap(int obj)
{
if (!isLocalPlayer)
{
return;
}
if (trapsCount != 0)
{
print("Placing trap...");
GameObject go_ = NetworkManager.singleton.spawnPrefabs[obj];
GameObject goIns = (GameObject)Instantiate(go_, cursor.transform.position, this.transform.rotation);
NetworkServer.Spawn(goIns);
print("Trap Placed");
trapsCount--;
RpcPlaySfx(goIns);
print("Playing SFX");
}
}
[ClientRpc]
void RpcPlaySfx(GameObject goRPC)
{
AudioSource.PlayClipAtPoint(trapClipPlace, goRPC.transform.position, 3f);
}
}
The problem is with the CmdPlaceTrap() method.
When i use editor as a host, i get all logs.
When i use editor as a client, i don’t get any logs at all. The command doesn’t run at all.
Regards