Argument 1: cannot convert from 'int' to 'string'

please someone show me how to fix this error
Argument 1: cannot convert from ‘int’ to ‘string’

 code error number: CS1503

my code :
using System.Collections;

using System.Collections.Generic;

using Mirror;

using UnityEngine;

using UnityEngine.AI;

public class PlayerMovement : NetworkBehaviour

{

[SerializeField] 



private NavMeshAgent agent = null; 

private Camera mainCamera; 



[Command]

private void CmdMove(Vector3 position)

{   

    if (!NavMesh.SamplePosition(position, out NavMeshHit hit,1f, NavMesh.AllAreas )) {return;}

    agent.SetDestination(hit.position);

}



public override void OnStartAuthority()

{

    mainCamera = Camera.main;

}

[ClientCallback]

private void Update() 

{

    if (!hasAuthority) {return;}

    if (!Input.GetButtonDown(1)) {return;}

    

    Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);

    if (Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity ))  {return;}

    CmdMove(hit.point); 

}

}

please help me

I fix this error
if (!Input.GetButtonDown(1)) {return;}
TO : if (!Input.GetMouseButtonDown(1)) {return;}

1 Like

Yes, that was your issue, remember the following:
Input.GetButtonDown asks for the name of the button in the form of a string to work, while Input.GetMouseButtonDown asks for the number of the button in the form of an int.

1 Like

and one more problem
player can’t move to click

Are there any errors in the console?

1 Like

no but recently
input system error applier
after that i change my unity input system new to both
and my error no more but player can’t move to click

I would double check the input system. Sometimes it reverts back to new or back to old. Try changing it to old, then after unity restarts change it to both.

1 Like

lol i fix this but another error i saw
:rofl: :rofl:
error type NullReferenceException: Object reference not set to an instance of an object
PlayerMovement.Update

my code using System.Collections;

using System.Collections.Generic;

using Mirror;

using UnityEngine;

using UnityEngine.AI;

public class PlayerMovement : NetworkBehaviour

{

[SerializeField] 



private NavMeshAgent agent = null; 

#region server

private Camera mainCamera; 

[Command]

private void CmdMove(Vector3 position)

{   

    if (!NavMesh.SamplePosition(position, out NavMeshHit hit,1f,NavMesh.AllAreas)) {return;}

    agent.SetDestination(hit.position);

}

#endregion

#region  Client

public override void OnStartAuthority()

{

    mainCamera = Camera.main;

}

    [ClientCallback]

    private void Update()

{

    if (hasAuthority) { return; }

    if (Input.GetMouseButtonDown(1))

    {

        return;

    }

    Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);

    if (Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity)) { return; }

    CmdMove(hit.point);

}

#endregion

}

Hi, it would help if you indicate the line on which the error occurs. For a null reference error, we need to identify which variable is null and then figure out why.

Line in cs.39 in error

Hi, since your script might be spaced differently, is it possible to copy and past the line itself instead of referring to it by line number?

Hi Sir , I saw error in this line : Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);

I can’t find it way to fix it error :disappointed:

HI Sir , sorry i fix it

before : if (hasAuthority) { return; }
if (Input.GetMouseButtonDown(1)) {return;}
Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity)) { return; }
CmdMove(hit.point);

and after Fix :
if (!hasAuthority) { return; }

    if (!Input.GetMouseButtonDown(1)) {return;}

    Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);

    if (!Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity)) { return; }

    CmdMove(hit.point);

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms