Script works in 2018.3.9f1 but doesn't work in 2019.2.13f1

So, I wrote a script to make a player moves in X position.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{

private Vector2 targetPosition;
public float Xincrement;
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
targetPosition = new Vector2(transform.position.x + Xincrement, transform.position.y);
transform.position = targetPosition;
}
}
}

but it simply didn’t work. So I sent it to a friend, asking him for help. He tested it on his computer, and it worked just fine. The difference is that his unity is in version 2018.3.9f1, while myunity is in version 2019.2.13f1.
Does it change anything? What should I do to make it work on my computer?

What debugging have you done?

Add Debug.Log statements to Update and inside your “if” statement. For all we know you just don’t have the script attached to an object running in the scene.

1 Like

Thank you for your answer.
I was able to fix it by reinstalling the unity. Probably some mistake during the installation.
But I’m really thankful for you taking your time to help me.
Thanks a lot!

1 Like