Сделал так
using UnityEngine;
using System.Collections;
//using UnityEngine.Networking;
public class GlVar : MonoBehaviour
{
public int t;
public GameObject Camera;
NetworkView networkView;
private Vector3 transfer;
public bool ClientCon;
public bool iServ;
float rotationX = 0F;
float rotationY = 0F;
float mouseSensitivity = 3.0f;
float minimumX = -360F;
float maximumX = 360F;
float minimumY = -60F;
float maximumY = 60F;
Quaternion originalRotation;
void Update()
{
if (ClientCon && (Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Mouse X") != 0 || Input.GetAxis("Mouse Y") != 0))
{
SetPos2();
}
}
//-----------------------------------------
public void SetPos2()
{
float V = Input.GetAxis("Vertical");
float H = Input.GetAxis("Horizontal");
float X = Input.GetAxis("Mouse X");
float Y = Input.GetAxis("Mouse Y");
this.GetComponent<NetworkView>().RPC("SetKey", RPCMode.All, V, H, X, Y);
}
[RPC]
void SetKey(float V, float H, float X, float Y)
{
// Движения мыши -> Вращение камеры
rotationX += X * mouseSensitivity;
rotationY += Y * mouseSensitivity;
rotationX = ClampAngle(rotationX, minimumX, maximumX);
rotationY = ClampAngle(rotationY, minimumY, maximumY);
Quaternion xQuaternion = Quaternion.AngleAxis(rotationX, Vector3.up);
Quaternion yQuaternion = Quaternion.AngleAxis(rotationY, Vector3.left);
Camera.transform.rotation = originalRotation * xQuaternion * yQuaternion;
// перемещение камеры
transfer = transform.forward * V;
transfer += transform.right * H;
transform.position += transfer * 2 * Time.deltaTime;
Camera.transform.position += transfer * 2 * Time.deltaTime;
print("V="+V.ToString());
}
public static float ClampAngle(float angle, float min, float max)
{
if (angle < -360F) angle += 360F;
if (angle > 360F) angle -= 360F;
return Mathf.Clamp(angle, min, max);
}
}
Не работает. Не пойму почему?