Need help translating js to c#

Need some help translating this js script to c#

It works just fine, but I would like it in c# as im most familiar with that and I have no clue how to translate it :confused:
You can destroy enemies by clicking them, and different enemies require a different amount of clicks.

#pragma strict

var amountOfClicks:int=0;

function OnMouseDown(){
   if(amountOfClicks>1)
   {
        Destroy(gameObject);
   }
   else{
     amountOfClicks++;
   }

In that case, make a C# Monobehavior class file named whatever you call this JS file.

Create an amountOfClicks as a public int

Declare the OnMouseDown() method (it’s special, so see Unity docs for the precise signature and capitalization).

Copy/paste your logic inside.

This is an excellent example for you to learn how easy it can be.

int amountOfClicks = 0;

void OnMouseDown()
{
  if( amountOfClicks > 1 )
  {
    Destroy(gameObject);
  }
  else
  {
    amountOfClicks++;
  }
}

Kurt: Thanks, I’m somewhat new to coding and was a bit confused. But you pointed me in the right direction :slight_smile:
And I tried translating it myself earlier but it didnt work (Dont know why), but now it works :smile:

For unity non ui input handling

//method called every frame
void Update()
{
//if mouse button down
if (Input.GetMouseButtonDown(0))
{
//do stuff here
}

}

Have you considered using Unity’s free UnityScript To C# automatic conversion tool ?