我已经习惯了这个网站,我感谢到目前为止帮助我的每个人。我的问题这次是一个CLient RPC,它不会在for循环中执行这个代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class CardSpawnerFirstNew : NetworkBehaviour {
public override void OnStartServer(){
distributeCards ();
}
IEnumerator Mycoroutine (bool CardDistribution){
yield return new WaitForSeconds(20f);
if (ClientScene.ready) {
Debug.Log ("the if statement worked");
NetworkManager NetM;
NetM = NetworkManager.singleton;
List<GameObject> Cards;
Cards = NetM.spawnPrefabs;
Debug.Log (Cards.Count);
for ( int i = 0;i<4;i++){
for (int j = 0; j < 8; j++) {
GameObject currentGameObject = Cards [Random.Range (0, Cards.Count)];
Cards.Remove (currentGameObject);
Debug.Log (currentGameObject);
Vector2 currentPosition = positionCalculator (i,j);
RpcInstantiateCards (currentPosition, currentGameObject);
}
}
}
}
public Vector2 positionCalculator (int I,int J){
Transform startPositionTransform;
Vector2 position, finalPosition;
List<Transform> startPositionsList;
Vector2 Increment = new Vector2 (1.41f, 0f);
NetworkManager netM = NetworkManager.singleton;
startPositionsList = netM.startPositions;
startPositionTransform = startPositionsList [I];
position = startPositionTransform.position;
finalPosition = position + J * Increment;
return finalPosition;
}
[Server]
public bool distributeCards(){
bool cardDistribution = false;
cardDistribution = true;
StartCoroutine ("Mycoroutine",cardDistribution);
return cardDistribution;
}
[ClientRpc]
public void RpcInstantiateCards (Vector2 position,GameObject card){
Debug.Log ("The RPC worked !!!");
Instantiate (card, position, Quaternion.identity);
}
}
这是控制台显示Console output
的内容每次for循环循环时调用RPc是什么问题,而不是它通过RPC而继续进行下一次迭代。
感谢您的每一次帮助。感谢您的时间。
答案 0 :(得分:0)
它不会起作用。 您无法每帧调用一次RPC方法,网络无法支持该调用速度。 Inastead在你的RPC中放了另一个for循环并调用它一次。