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 /
avatar image
0
Question by bgacem · May 31, 2011 at 02:14 PM · javascriptbooleankinectgestures

Gestures in javascript

Hello, i have a problem. I'm trying to create a simple game in Unity in which the character has to perform a gesture with his arm. I want to create the gestures with multiple collisions in a specific order. At the moment I have 5 spheres in a row which i want the character to activate from left to right. I tried to put booleans on every sphere and when the character collides with the sphere the boolean will be set to true. When enough booleans are set to true (in our case 3) the character has performed the gesture good enough.

In the beginning all booleans are set to false but when they are set true they turn back immediately.

This is our code: var aSound: AudioClip; var Sphere1 : boolean = false; var Sphere2 : boolean = false; var Sphere3 : boolean = false; var Sphere4 : boolean = false; var Sphere5 : boolean = false; var aantalGeraakt : int; function OnCollisionExit(theCollision : Collision){ if(gameObject.name == "Sphere1" && theCollision.gameObject.tag == "Rechts"){ Debug.Log("Hit Sphere1"); audio.PlayOneShot(aSound); Sphere1 = true; aantalGeraakt ++; } if(gameObject.name == "Sphere2" && theCollision.gameObject.tag == "Rechts"){ Debug.Log("Hit Sphere2"); audio.PlayOneShot(aSound); Sphere2 = true; aantalGeraakt ++; } if(gameObject.name == "Sphere3" && theCollision.gameObject.tag == "Rechts"){ Debug.Log("Hit Sphere3"); audio.PlayOneShot(aSound); Sphere3 = true; aantalGeraakt ++; } if(gameObject.name == "Sphere4" && theCollision.gameObject.tag == "Rechts"){ Debug.Log("Hit Sphere4"); audio.PlayOneShot(aSound); Sphere4 = true; aantalGeraakt ++; } if(gameObject.name == "Sphere5" && theCollision.gameObject.tag == "Rechts"){ Debug.Log("Hit Sphere5"); audio.PlayOneShot(aSound); Sphere5 = true; aantalGeraakt ++; } Debug.Log(aantalGeraakt); Debug.Log("blokkie 2: " +Sphere2+ " - " + Sphere3); return; }

I have the feeling that the whole script is in some sort of loop which resets all variables back to default.

Who knows how to solve this problem?

Thanks in advance

Comment
Add comment · Show 2
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 G_Sacristan · May 31, 2011 at 04:52 PM 0
Share

this code is attached to several gameObjects, right?

well in each script there will be different values for each variable...

So it means that the last script will write in console its contents of variables... I would prefer to use one script with a link to each gameObject, that will make your job easier and you will get correct boolean values.

avatar image aldonaletto · May 31, 2011 at 04:55 PM 0
Share

Where do you set the Sphere booleans to false? (except the initialisation)

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by G_Sacristan · May 31, 2011 at 05:00 PM

this code is attached to several gameObjects, right?

well in each script there will be different values for each variable...

So it means that the last script will write in console its contents of variables... I would prefer to use one script with a link to each gameObject, that will make your job easier and you will get correct boolean values.

 var spheres: GameObject[];//set size to 5 and add all spheres
 
 var aantalGeraakt : int;
 
 function OnCollisionExit(theCollision : Collision)
 {
      for(var i=0;i<spheres.length;i++)
      {
           if(spheres[i]==theCollision.gameObject&&theCollision.gameObject.tag == "Rechts")
           {
                audio.PlayOneShot(aSound);
                aantalGeraakt ++;
           }
      }
 }
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 G_Sacristan · May 31, 2011 at 05:01 PM 0
Share

if u need something more specific then ask and ill make code for you!

avatar image bgacem · Jun 01, 2011 at 11:20 AM 0
Share

Hey SCape_games,

First off, I'd like to thank you for your help. You were right about the spheres having their own variables. I integrated the script you gave but there were some difficulties. On which gameObject do I have to connect the script to. Because when I connect it to the gameObject 'Sphere1' the collision only takes place with that single sphere. And if I connect the script to all of the spheres I have the same problem that each sphere has it's own variables. This is how the script looks like at this moment:

var spheres : GameObject[];

var aantalGeraakt : int; var aSound : AudioClip;

 function OnCollisionExit(theCollision : Collision)
 {
     for(var i=0;i<spheres.length;i++)
     {
           if(spheres[i]==gameObject && theCollision.gameObject.tag == "Rechts"){
             audio.PlayOneShot(aSound);
             aantalGeraakt ++;
             i++;
             Debug.Log("i = " + i);
             Debug.Log("aantalGeraakt = " + aantalGeraakt);
         }
     }
 }

I also changed "spheres[i]==theCollision.gameObject" to "spheres[i]==gameObject" because the collision doesn't happen as it was. How do we give the spheres the same variables?

Thanks in advance.

avatar image
0

Answer by G_Sacristan · Jun 01, 2011 at 12:50 PM

first of all add script to empty object (at least not on sphere), then

 var spheres : GameObject[];
 var aantalGeraakt : int;
 var aSound : AudioClip;
 
 function OnCollisionExit(theCollision: Collision)
 {
     for(var i=i;i<spheres.length;i++)
     {
          if(spheres[i]==theCollision.gameObject)//check if the collision gameObject matches one of spheres
          {
               print(Sphere: +spheres[i].name);//print which sphere got collision
               audio.PlayOneShot(aSound);
               aantalGeraakt++; //no need to increase index, because its already done in loop
          }
     }
 }

If i understood corectly, u want to check if there is a collision with sphere and so u want to get which one collides Cheers!

Comment
Add comment · Show 1 · 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 bgacem · Jun 01, 2011 at 02:04 PM 0
Share

Hello, here I am again. I tried everything you said and connected the script to an empty game object but for some reason I don't get any reaction from the spheres when the character's right hand (which is also a sphere and has the target 'Right') collides. It only works when the script is connected to the sphere itself. Do I have to add specific components to the spheres or to the hand to let the collision take place?

avatar image
0

Answer by G_Sacristan · Jun 01, 2011 at 04:31 PM

i got an arror, sorry

 var spheres : GameObject[];
 var aantalGeraakt : int;
 var aSound : AudioClip;
 
 function OnCollisionExit(theCollision: Collision)
 {
     for(var i=0;i<spheres.length;i++)
     {
          if(spheres[i]==theCollision.gameObject)//check if the collision gameObject matches one of spheres
          {
               print(Sphere: +spheres[i].name);//print which sphere got collision
               audio.PlayOneShot(aSound);
               aantalGeraakt++; //no need to increase index, because its already done in loop
          }
     }
 }
Comment
Add comment · 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
0

Answer by G_Sacristan · Jun 01, 2011 at 04:31 PM

i got an arror, sorry

 var spheres : GameObject[];
 var aantalGeraakt : int;
 var aSound : AudioClip;
 
 function OnCollisionExit(theCollision: Collision)
 {
     for(var i=0;i<spheres.length;i++)
     {
          if(spheres[i]==theCollision.gameObject)//check if the collision gameObject matches one of spheres
          {
               print(Sphere: +spheres[i].name);//print which sphere got collision
               audio.PlayOneShot(aSound);
               aantalGeraakt++; //no need to increase index, because its already done in loop
          }
     }
 }
Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Shooting only once, returning boolean as false 2 Answers

Sending the C# function parameter to JS function. 1 Answer

Gesture Sequences in javascript 1 Answer

Compiler error UCE0001: ';' expected 1 Answer

OnGUI Script Not Working With Boolean... 1 Answer


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