Not able to use else statement without error

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

public class playerController : MonoBehaviour
{
    public float movementSpeed;
    private float horizontalMovement;
    private float verticalMovement;
    public float jumpSpeed;
    public bool isGrounded;
    public bool isJumping;

    // Update is called once per frame
    void Update()
    {
        horizontalMovement = Input.GetAxis("Horizontal");
        transform.Translate(Vector2.right*horizontalMovement*Time.deltaTime*movementSpeed);
        verticalMovement = Input.GetAxis("Jump");
        transform.Translate(Vector2.up*verticalMovement*Time.deltaTime*jumpSpeed);
        if (horizontalMovement != 0)
        {
           GetComponent<Animator>().SetBool("isRunning", true);
        }
        else
        {
            GetComponent<Animator>().SetBool("isRunning", false);
        }
       
        function OnCollisionEnter (col : Collision)
        {
        if (col.gameObject.tag == "Ground" )
        {
            SetBool("isGrounded", true);
        }
        else
        {
            SetBool("isGrounded", false);
        }
        }
    }  
}

I tried to use this code, but it had a “playerController.cs(30,51): error CS1513: } expected”. I counted and i don’t think I am missing anything. What am I doing wrong?

It looks like you are trying to implement unitys OnCollisionEnter method, but it looks like you are trying to implement it inside the Update. Im pretty sure that shouldn’t be there.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerController : MonoBehaviour
{
    public float movementSpeed;
    private float horizontalMovement;
    private float verticalMovement;
    public float jumpSpeed;
    public bool isGrounded;
    public bool isJumping;
    // Update is called once per frame
    void Update()
    {
        horizontalMovement = Input.GetAxis("Horizontal");
        transform.Translate(Vector2.right*horizontalMovement*Time.deltaTime*movementSpeed);
        verticalMovement = Input.GetAxis("Jump");
        transform.Translate(Vector2.up*verticalMovement*Time.deltaTime*jumpSpeed);
        if (horizontalMovement != 0)
        {
           GetComponent<Animator>().SetBool("isRunning", true);
        }
        else
        {
            GetComponent<Animator>().SetBool("isRunning", false);
        }
    }

    private void OnCollisionEnter (Collision other)
    {
        if (col.gameObject.tag == "Ground" )
        {
            SetBool("isGrounded", true);
        }
        else
        {
            SetBool("isGrounded", false);
        }
    }
}

At a glance it appears you tried to use code that was intended for UnityScript not C#. Be careful when you look up very old tutorials and forum posts as there were a lot of people using UnityScript. Code written in it will have to be converted to C# before it can be used.