Updating an animator with 2D NPC position

Hi

Can someone just tell me what’s wrong with this script? I have this attached to an NPC object which is moved via another script. I want to update an animator with the movement of the NPC.

However i get “Syntax error, ‘,’ expected” on line 17, which is the second IF statement.

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

public class NPC_Controller : MonoBehaviour
{
    var old_pos : float;

    public Animator animator;
   
    void Update()
    {
        if (old_pos < transform.position.x)
        {
            animator.SetFloat("Horizontal",1);
        }
        if (old_pos > transform.position.x)
        {
            animator.SetFloat("Horizontal",-1);
        }
        old_pos = transform.position.x;
    }
}

@oliver_unity892

You are not using C# syntax for your old_pos variable, which too should be renamed;

Var can be only used inside methods, not in fields.

And seems like your old_pos is written like UnityScript, which is no longer used, did you pick this part from some tutorial perhaps?

See some C# guide like this one:
https://www.w3schools.com/cs/cs_variables.asp

Edit:
Are use using IDE? As you should already see red underline for the error part…