Ambiguity

How to fix this error: Ambiguity between ‘Movement.ScreenWidth’ and ‘Movement.ScreenWidth’ Assembly-CSharp

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
    //variables
    public float moveSpeed = 300;
    public GameObject character;
    private Rigidbody characterBody;
    private float ScreenWidth;
    // Use this for initialization
    void Start()
    {
        ScreenWidth = Screen.width;
        characterBody = character.GetComponent<Rigidbody>();
    }
    // Update is called once per frame
    void Update()
    {
        int i = 0;
        //loop over every touch found
        while (i < Input.touchCount)
        {
            if (Input.GetTouch(i).position.x > ScreenWidth / 2)
            {
                //move right
                RunCharacter(1.0f);
            }
            if (Input.GetTouch(i).position.x < ScreenWidth / 2)
            {
                //move left
                RunCharacter(-1.0f);
            }
            ++i;
        }
    }
    void FixedUpdate()
    {
#if UNITY_EDITOR
        RunCharacter(Input.GetAxis("Horizontal"));
#endif
    }
    private void RunCharacter(float horizontalInput)
    {
        //move player
        characterBody.AddForce(new Vector2(horizontalInput * moveSpeed * Time.deltaTime, 0));
    }
}

I pasted your code in empty project and there are no any errors.

1 Like

This smells like a compilation problem where there are duplicate symbols.

Make a Plugins folder, create a temp script in there, let Unity recompile, then delete your temp script.

That will most likely fix the issue.

Problem Solved, thanks for helping.