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) ![]()
Thanks in advance for your time / Fredrik in Sweden