Ответ: Маленькая проблемка в моей сети
using UnityEngine;
[RequireComponent(typeof(NetworkView))]
public class PlayerScript : MonoBehaviour
{
public float moveSpeed = 2;
public float turnSpeed = 90;
private CharacterController _controller;
private Transform _thisTransform;
public GameObject fpsPrefab;
public GameObject locomotionPrefab;
private GameObject controlledObject;
public void Start()
{
_controller = GetComponent<CharacterController>();
_thisTransform = transform;
}
public void Awake()
{
if (!networkView.isMine)
{
enabled = false;
controlledObject = Instantiate(locomotionPrefab) as GameObject;
}
else
{
controlledObject = Instantiate(fpsPrefab) as GameObject;
}
}
public void Update()
{
if (networkView.isMine)
{
_controller.Move(_thisTransform.forward * moveSpeed * Time.deltaTime * Input.GetAxis("Vertical") +
Vector3.down * 10.0f * Time.deltaTime);
Quaternion rot = Quaternion.AngleAxis(
turnSpeed * Time.deltaTime * Input.GetAxis("Horizontal"), Vector3.up);
_thisTransform.rotation *= rot;
}
}
public void OnDestroy()
{
Destroy(controlledObject);
}
public void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
if (stream.isWriting)
{
Vector3 pos = controlledObject.transform.position;
stream.Serialize(ref pos);
}
else
{
Vector3 posReceive = Vector3.zero;
stream.Serialize(ref posReceive);
controlledObject.transform.position = posReceive;
}
}
}
|
где именно ?
|