Hey! I made a 2D simple platformer, and the character has a gun. The gun always looking at the mouse. In multiplayer, the other clients' gun rotating to the same direction. How can I fix it? The code: Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class playerGun : MonoBehaviour { public float offset; void Start() { } void Update() { Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position; float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.Euler(0f, 0f, rotZ + offset); } }
Read the UNET manual. Use NetworkBehaviour + isLocalPlayer checks. Send direction to server to sync to other clients.
Thank for you help have fixed party of probleme . I have split gun and player game object, i give network Id and network transform each. On void start of the player controller have Instantiate the gun . The gun have script for follow the mousse . And player ObjectToFollow. But dont worker for follow player . I need to find how make one game object follow the player prefab. If you have good tuto for learn unet . Code (csharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; public class GunScript : NetworkBehaviour { public GameObject objectToFollow; public float speed = 10.0f; // Use this for initialization void Start () { } void Update () { Vector2 position = transform.position; position.y = objectToFollow.transform.position.y; position.x = objectToFollow.transform.position.x; transform.position = position; Vector2 direction = (Input.mousePosition) - transform.position; float angle = Mathf.Atan2 (direction.y, direction.x) * Mathf.Rad2Deg; Quaternion rotation = Quaternion.AngleAxis (angle, Vector3.forward); transform.rotation = Quaternion.Slerp (transform.rotation, rotation, speed * Time.deltaTime); } } [CODE/]