A simple script from JavaScript to and C #

Hi,

I started working with Unity just a few days ago. I never learn any programming language and I’m currently to make examples from youtube. I would like to create a shooting bow or be able to throw objects.
Unfortunately, one of the tutorials is a script in JavaScript, and in Unity I can not create it.
Can someone help me write the same, but in C #
Below I am sending the script and the final result.

In this project I have another scripts to:

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


public class BowScript : MonoBehaviour
{
    float _charge;

    public float chargeMax;
    public float chargeRate;

    public KeyCode fireButton;

    public Transform spawn;
    public Rigidbody arrowObj;

    void Update()
    {
        if(Input.GetKey(fireButton) && _charge < chargeMax)
        {
            _charge += Time.deltaTime * chargeRate;
            Debug.Log(_charge.ToString());
    }
    if(Input.GetKayUp(fireButton))
        {
        Rigidbody arrow = Instantiate(arrowObj, spawn.position, Quaternion.identity) as Rigidbody;
    arrow.AdForce(spawn.forward * _charge, ForceMode.Impulse);
        _charge = 0;
}
}

and the second one

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


public class ArrowScript : MonoBehaviour
{
    public int damage;

    void OnTriggerEnter(Collider col)
    {
        if (col.GetComponet<EnemyStats>())
        {
            EnemyStats stats = col.GetComponent<EnemyStats>();
            stats.Hit(damage);
        }


    }
}

Thank you in advance for all your help.

You only need to change four things in that script to make it C#:

  • Declare “health” as int instead of var
  • Remove “: int” after declaring “health”
  • Declare “isHit” as bool instead of var
  • Change “function Update()” to “void Update()”

Unity has scripting tutorials here: Learn game development w/ Unity | Courses & tutorials in game design, VR, AR, & Real-time 3D | Unity Learn

I’d switch to a more up to date tutorial that’s in C#.