Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by 3janeiscool · Dec 28, 2016 at 06:38 PM · newbiemergejava to c#

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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);
 
         }
     }
 }



Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image 3janeiscool · Dec 30, 2016 at 10:47 AM 1
Share

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!

avatar image TonyVT 3janeiscool · Dec 30, 2016 at 01:47 PM 1
Share

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!

avatar image
0

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!

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image 3janeiscool · Dec 30, 2016 at 11:24 AM 0
Share

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

avatar image dignifiedweb 3janeiscool · Dec 30, 2016 at 01:55 PM 0
Share

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!

avatar image 3janeiscool dignifiedweb · Dec 30, 2016 at 03:55 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

85 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Merging two projects into one 0 Answers

Unity Reloaded My Project But Reset every thing (i got an error that said the were complier errors in the script and i had to Load Default Layout!) 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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges