Merge static C# script and old java script function (NewtonVR) Oculus Touch

Hi. i’m in greet need of help! I’m a total noob of scripting and cant figure out how to keep a script intact (working functions) and to ad new functions to it.

Im developing a remake of the old classic Dactyl Nightmare VR game from the 90,s and i am forced to use the free NewtonVr setup to gain the function of Oculus Touch controllers. (this is not possible in the AvatarSDK)

This is the premade working script from NewtonVR to get the “Touch trigger” to fire the projectile, and i assume it can’t be messed with… without removing functions.

using UnityEngine;
using System.Collections;

namespace NewtonVR.Example
{
    public class NVRExampleGun : NVRInteractableItem
    {
        public GameObject BulletPrefab;

        public Transform FirePoint;

        public Vector3 BulletForce = new Vector3(0, 0, 250);

        public override void UseButtonDown()
        {
            base.UseButtonDown();

            GameObject bullet = GameObject.Instantiate(BulletPrefab);
            bullet.transform.position = FirePoint.position;
            bullet.transform.forward = FirePoint.forward;

            bullet.GetComponent<Rigidbody>().AddRelativeForce(BulletForce);

        }
    }
}

This is the function in my old Java script i want to merge:

var ammoCount : int = 9; //how much ammo in our clip
var fireRate : float = 0.5; //how quickly we can shoot our grenades
private var nextFire : float =0.0;

}
 
function Fire () {
 
if (ammoCount > 0) {
 
if (Input.GetButtonDown("Fire1") && Time.time > nextFire) {
 
nextFire = Time.time + fireRate;
 
InstantiateGrenade();
 
ammoCount -=1;
 
}

Note: the “Fire1” finction i my Js. is Not to be working in the c#, but is replaced with:

public override void UseButtonDown()
         {
             base.UseButtonDown();

And i would also like to merge the animation running from the old script. (this is optional and not a crisis!)

function lizzard () {
 
if(ammoCount < 1 && totalAmmo > 9) { //if we have less than 1 bullet then we can reload
  
Obj1.GetComponent.<Animation>().Play("playerfly");
Obj2.GetComponent.<Animation>().Play("lizzard_hide");
 
ammoCount += reloadAmount; //adds ammo to our "clip" based off the reloadAmount
totalAmmo -= reloadAmount; //subtracts whatever the reloadAmount was from our total ammo every time we reload
 
}

}

I Will of course add anyone helping me with this to my credits in the final release on Oculus Store (Free ware) :slight_smile:

Thanks in advance for your time / Fredrik in Sweden

I absolutely don’t get the question. Do you want to merge into C# your js code?
Something like this:

using UnityEngine;
using System.Collections;

namespace NewtonVR.Example
{
    public class NVRExampleGun : NVRInteractableItem
    {
        public GameObject BulletPrefab;

        public Transform FirePoint;

        public Vector3 BulletForce = new Vector3(0, 0, 250);

        private int ammoCount = 9; //how much ammo in our clip
        private float fireRate = 0.5f; //how quickly we can shoot our grenades
        private float nextFire = 0;

        public override void UseButtonDown()
        {
            base.UseButtonDown();

            Fire();
        }

        public void Fire()
        {

            if (ammoCount > 0 && Time.time > nextFire)
            {
                    nextFire = Time.time + fireRate;
                    InstantiateGrenade();
                    ammoCount -= 1;
            }

        }

        public void InstantiateGrenade()
        {
            GameObject bullet = GameObject.Instantiate(BulletPrefab);
            bullet.transform.position = FirePoint.position;
            bullet.transform.forward = FirePoint.forward;

            bullet.GetComponent<Rigidbody>().AddRelativeForce(BulletForce);

        }
    }
}

My original comment:

Are you just trying to get whether you
pressed the touch controller’s trigger
down? If that’s the case, why don’t
you use OVRInput? OVRInput would be
something like this:

// Right trigger button on touch controller
if(OVRInput.GetDown(OVRInput.Button.SecondaryIndexTrigger,

OVRInput.Controller.Touch)
{
Debug.Log(“I pressed the right controller’s index trigger button”);
}

Make sure you download the Oculus
Utilities from the Oculus dev website:
https://developer.oculus.com/

Next, review the diagram here for
enumerations:
https://developer3.oculus.com/documentation/game-engines/latest/concepts/unity-ovrinput/#unity-ovrinput-touch

Otherwise, I’m not sure what you’re
asking. Hope that helps.

Hi, I didn’t have a lot of time to comment before. It seems like I was very wrong with my answer.

So, I guess for one, it would help for some context, didn’t know you were the original creator of the Unity Version of this game:

Second, why are you using that open-source framework for hand interactions as opposed to the Avatar SDK? I’m just confused by what you’re trying to accomplish, I might be able to help.

As suggested above, are you trying to consolidate the javascript script to C#?

Also, it doesn’t seem like you’re new to scripting if you’re handling inheritance, etc. Plus, the original game you made in unity looks pretty impressive, so good work!