- Home /
isLocalPlayer set to true on child
Hello,
I am having an issue where I have a "PlayerManager" which is an empty gameobject that contains another empty gameObject as well as the Player gameobject. This is so the Player (A ball) can roll and not interfere with the attachments that go with the 2nd empty gameObject. The problem comes in mixing the Unity Networking into the equation. Since the first Empty gameObejct is root it holds the isLocalPlayer function but the player gameObject which has the movements attached to it does not hold isLocalPlayer.
Either I need to put the movement script on the root object and make it so that it only effects the player object or I need to force isLocalPlayer onto thePlayer child object.
Movement Script: using UnityEngine; using System.Collections; using UnityEngine.Networking;
public class PlayerController : NetworkBehaviour
{
public float speed;
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
if (!isLocalPlayer)
return;
float moveHorizontal = Input.GetAxisRaw("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = Camera.main.transform.forward * moveVertical * speed * Time.deltaTime;
rb.AddForce(movement);
movement = Camera.main.transform.right * moveHorizontal * speed * Time.deltaTime;
rb.AddForce(movement);
}
void Update()
{
}
}
The Attachments game Object uses a script to always follow the camera (Rotate on a static axis) while it follows the players movements around the map. The player uses the Cameras direction to determine forward etc. I use the MouseOrbit script to achieve this as it works perfect for it.
Your assistance would be great as I am sure I am missing something obvious :/