Answers for "Assets\Scripts\PlayerMovement.cs(13,14): error CS0103: The name 'IsLocalPlayer' does not exist in the current context"

C#
0

Assets\Scripts\PlayerMovement.cs(13,14): error CS0103: The name 'IsLocalPlayer' does not exist in the current context

using MLAPI;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    CharacterController cc;
    public Transform cameraTransform;
    float pitch = 0f;

    // Start is called before the first frame update
    void Start()
    {
        if (!IsLocalPlayer)
        {
            cameraTransform.GetComponent<AudioListener>().enabled = false;
            cameraTransform.GetComponent<Camera>().enabled = false;
        }
        else
        {
            cc = GetComponent<CharacterController>();
        }
        
    }

    // Update is called once per frame
    void Update()
    {
        if (IsLocalPlayer)
        {
            MovePlayer();
            Look();
        }
        
    }

    void MovePlayer()
    {
        Vector3 move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
        move = Vector3.ClampMagnitude(move, 1f);
        move = transform.TransformDirection(move);
        cc.SimpleMove(move * 5f);
    }

    void Look()
    {
        float mousex = Input.GetAxis("Mouse X") * 3f;
        transform.Rotate(0, mousex, 0);
        pitch -= Input.GetAxis("Mouse Y") * 3f;
        pitch = Mathf.Clamp(pitch, -45f, 45f);
        cameraTransform.localRotation = Quaternion.Euler(pitch, 0, 0);
    }
}
Posted by: Guest on October-01-2021

Code answers related to "Assets\Scripts\PlayerMovement.cs(13,14): error CS0103: The name 'IsLocalPlayer' does not exist in the current context"

C# Answers by Framework

Browse Popular Code Answers by Language