How do i convert this into c#

I found this script off of a forum and it appears to be the only one that could solve my issue. That being, how to make an enemy follow the closet player. Unfortunately, it’s in some other coding language. So can anyone help me translate this into C#?

func chase(): var players = get_tree().get_nodes_in_group(“players”) var min_dist = chase_range target = null for p in players: var cur_dist = p.global_position.distance_to(self.global_position) if cur_dist <= min_dist: target = p min_dist = cur_dist if is_instance_valid(target): direction = target.position - position else: wander() direction = direction.normalized() velocity = direction * chase_speed if velocity.x > 0: facing = “r” if velocity.x < 0:

The language doesn’t look like JavaScript (UnityScript) or Boo, which were the only other two languages Unity supported in the past, as far as I’m aware. Wherever you got this from, it doesn’t seem like it’s related to Unity, and converting it into a C# script that interfaces with Unity’s API would be basically writing it from scratch.

Searching online for “Unity follow closest object”, this was the first result:

Maybe this will help instead.

Scripting questions are best asked in the Scripting forum.

Fixed, Thanks