我想做什么·启动应用程序1,应用程序2·如果我在应用程序1中按下按钮,即使在应用程序2中也会按下按钮(更改点击事件或bool类型变量)
我尝试了什么(我将 Unity 文件放在这里) https://drive.google.com/open?id=1aV-1SiB56L3JGVzWqAmqc85PYFNW1268
将以下内容添加到按钮的对象中,单击
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class MoviePlay : NetworkBehaviour {
[SyncVar]
bool IsPlay = false;
void Update(){
if(IsPlay){
Debug.Log("再生中");
}
}
public void OnClick(){
CmdOnClick();
}
[Command]
void CmdOnClick(){
IsPlay = true;
}
}
结果:控制台显示为 1 找不到同步消息的目标并且未同步
- - -添加 - - -
我尝试过这个。按钮(播放器对象)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
public class PushButton : NetworkBehaviour {
[SerializeField]
GameObject DebugScript;
public void OnClickButton(){
NetworkInstanceId target = DebugScript.GetComponent<NetworkIdentity>().netId;
CmdSendMessageToServer(target, "DebugText");
}
[Command]
public void CmdSendMessageToServer (NetworkInstanceId target, string message)
{
NetworkServer.FindLocalObject(target).SendMessage(message);
}
}
调试脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DebugScript : MonoBehaviour {
void DebugText(){
Debug.Log("再生");
}
}