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) :)
Thanks in advance for your time / Fredrik in Sweden
Answer by TonyVT · Dec 29, 2016 at 01:58 PM
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);
}
}
}
Wow thank you so mush for this! =) It work right out of the box!
i'm sorry for my hieroglyphic question above, but you deciphered it right away! (y)
And as always i'm going to learn something from this that i could certainly use later on in another context.
Best regards to you TonyVT and a happy new year to you!
I'm glad to have helped you! Happy new year to you and to your gamedev $$anonymous$$m from me and all the Immotionar (www.immotionar.com) $$anonymous$$m! Let me know when the game will come to life! Hope that 2017 will be a great year for virtual reality!
Answer by dignifiedweb · Dec 29, 2016 at 02:16 PM
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: https://forums.oculus.com/vip/discussion/9030/dactyl-nightmare-2-0-old-school-vr/p3
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!
Hi. sorry to say i'm a copypaste guy and all my scripts are more or less copied or reverse engineered from others work. I have to get my ass out of the family couch and star learning c# and java :)
About the if(OVRInput.GetDown
I tried that from others suggestions before i started with NewtonVR, but could note make it work at all. only got error that the OVR input class was missing/not set. and it didn't made any difference from what object or prefab i tried....
also my old scripts where using L$$anonymous$$B and Fire1,
thanks for your answer / Best Regards, Fredrik
I figured TonyVT above answered your question, so I was trying to suggest something else. I'm glad you found what you were looking for. Happ new year to the both of you guys!
Also, regarding OVRInput. It does not come default with Unity, so you'll need to download the Oculus Utilities from the Oculus website to be able to use it. It's a DLL that gets extracted to the plugins directory of your assets folder. You can P$$anonymous$$ me here or on the oculus forums, I go by the same alias, I could help you with that if you want or send you a working example unity project. Cheers!
Great thanx i will send you a P$$anonymous$$ right away!
always better to use the stuff com$$anonymous$$g out from the vendor!
/ Thanx! :D
Your answer
Follow this Question
Related Questions
Merging two projects into one 0 Answers
Respawn point 1 Answer
I need to create artificial gravity ( like a fake fake centrifugal effect) 2 Answers
Platformer Jump Script Without AddForce 0 Answers