您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
40 行
881 B
40 行
881 B
using MLAPI;
|
|
using MLAPI.Messaging;
|
|
using System;
|
|
using UnityEngine;
|
|
|
|
public class PlayerInput : NetworkedBehaviour
|
|
{
|
|
private Character character;
|
|
|
|
public void Awake()
|
|
{
|
|
character = GetComponent<Character>();
|
|
}
|
|
|
|
public override void NetworkStart()
|
|
{
|
|
if (IsClient)
|
|
{
|
|
SimulationManager.Singleton.OnSimulationUpdate += SimulationUpdate;
|
|
}
|
|
}
|
|
|
|
private void SimulationUpdate(float time, float deltaTime)
|
|
{
|
|
if (Input.GetMouseButton(0))
|
|
{
|
|
RaycastHit hit;
|
|
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
|
|
{
|
|
InvokeServerRpc(SendPlayerInput, hit.point);
|
|
}
|
|
}
|
|
}
|
|
|
|
[ServerRPC]
|
|
public void SendPlayerInput(Vector3 position)
|
|
{
|
|
character.SetMovementTarget(position);
|
|
}
|
|
}
|