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 /
This question was closed Dec 25, 2015 at 02:03 AM by KnightRiderGuy for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by KnightRiderGuy · Dec 24, 2015 at 04:36 PM · c#scripting problemscripting beginnerscriptingproblem

Try part of C# not being Read

I'm not very good at code so perhaps someone can point me in the right direction as to why this part of the code is not being reached. If I comment all of the update out above it then it does read. So I'm sure I'm buggering up something not being too familiar with it.

 try
         {
             MoveObject(sp.ReadByte());
             print(sp.ReadByte());
         }
         catch (System.Exception) {
 
         }


This is the code with the rest of the Update.

     // Update is called once per frame
     void Update () {
         amountToMove = speed * Time.deltaTime; // New Test For Arduino Move Cube
             //print("BytesToRead" +sp.BytesToRead);
             message2 = sp.ReadLine();
             
         string message = sp.ReadLine(); //get the message...
         if(message == "") return; //if its empty stop right here
         // parse the input to a float and normalize it (range 0..1) (we could do this already in the Arduino)
 
         float input =  1 -  float.Parse (message) / 100f;
         // set the slider to the value
         float oldValue = slider.value; // -------- this is new
         slider.value = input;
 
         // after the slider is updated, we can check for the other things for example play sounds:
 
         if (source.isPlaying) return; // if we are playing a sound stop here
 
         // else check if we need to play a sound and do it
         if (slider.value > 0.9f && oldValue <= 0.9f) // ---------this has changed
             source.PlayOneShot (BrightnessAudioClips [Random.Range (0, BrightnessAudioClips.Length)]);
 
         else if (slider.value < 0.15f && oldValue >= 0.15f) //----------this has changed
             source.PlayOneShot (DarknessAudioClips [Random.Range (0, DarknessAudioClips.Length)]);
         
         try
         {
             MoveObject(sp.ReadByte());
             print(sp.ReadByte());
         }
         catch (System.Exception) {
 
         }
     }
Comment
Add comment · Show 1
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 KnightRiderGuy · Dec 24, 2015 at 06:21 PM 0
Share

Ok I found that if I moved the Try and the catch to the top of the Update Then it seems to work although for my particular purpose I'm not sure if this is the best way to do it.

The button press data from the Arduino is just going to be used to activate an animation on another script and game object, that's if I can get some help with that whole other cluster F.... ;)

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by KnightRiderGuy · Dec 25, 2015 at 02:03 AM

Well, I'm surprises no one chimed in on this seeing how easy a fix it turned out to be. Seems I had to place the Try and the Catch at the beginning of the Update.

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

Follow this Question

Answers Answers and Comments

44 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

Related Questions

How to rotate RigidBodyFPSController (C#) 1 Answer

How to add a editing option to variables in a script in Inspector? 0 Answers

Side-scrolling Enemy AI not shooting in the right direction 0 Answers

How to make a random object generator that responds to simple touch? 0 Answers

How can i run a script with a single key press? 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