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 biofanir · Dec 13, 2016 at 09:54 AM · inputstring

ERROR ! Input string was not in the correct format

Input string was not in the correct format Anybody know why this error is happening? Input string was not in the correct format System.Int32.Parse (System.String s) This is my script.

i'm use ARDUINO in this Script

my script :

using UnityEngine; using System.Collections; using System.IO.Ports;

public class DiceSwipeControl : MonoBehaviour { SerialPort myport = new SerialPort ("\\\.\\COM13",9600);

     // Static Instance of the Dice
     public static DiceSwipeControl Instance;
 #region Public Variables
     // Orignal Dice
     public GameObject orignalDice;
     //dice resultant number..
     public int diceCount;
     //dice play view camera...
     public Camera dicePlayCam;
     //Can Throw Dice
     public bool isDiceThrowable = true;
     public GUIText gui;
     public Transform diceCarrom;
 #endregion

 #region Private Varibles
     private GameObject diceClone;
     private Vector3 initPos;
     private float initXpose;
     private float timeRate;
     // To Save Camera Postion
     private Vector3 currentCampPos;
     Vector3 objectPos;
     internal float diceThrowInit;
 #endregion

     void Awake ()
     {
             Instance = this;

     }

     void Start ()
     {
             myport.Open ();
             generateDice ();
     }

     void Update ()
     {
     string datadariarduino = myport.ReadLine ();
     int dfai = int.Parse (datadariarduino);
     print ("arduino siap!");
     print (dfai);

             if (isDiceThrowable)
             {
             if (dfai == 1) 
                 {
                         initPos = Input.mousePosition;
                         initXpose = dicePlayCam.ScreenToViewportPoint (Input.mousePosition).x;
                 }
                 Vector3 currentPos = Input.mousePosition;
                 currentPos.z = 25f;
                 Vector3 newPos = dicePlayCam.ScreenToWorldPoint (new Vector3(currentPos.x,currentPos.y,Mathf.Clamp(currentPos.y/10,5,70)));
                 newPos.y = Mathf.Clamp(newPos.y, -114.5f, 100);
                 newPos = dicePlayCam.ScreenToWorldPoint (currentPos);
                 if (Input.GetMouseButtonUp (0)) 
                 {
                     initPos = dicePlayCam.ScreenToWorldPoint (initPos);
     
                     enableTheDice ();
                     addForce (newPos);
                     isDiceThrowable = false;
                             
                     StartCoroutine (getDiceCount ());
                 }
             }
     }

     void addForce (Vector3 lastPos)
     {
             diceClone.GetComponent<Rigidbody>().AddTorque(Vector3.Cross(lastPos, initPos) * 1000, ForceMode.Impulse);
             lastPos.y += 12;
             diceClone.GetComponent<Rigidbody>().AddForce (((lastPos - initPos).normalized) * (Vector3.Distance (lastPos, initPos)) * 30 * diceClone.GetComponent<Rigidbody>().mass);
     }

     void enableTheDice ()
     {        
             diceClone.transform.rotation = Quaternion.Euler (Random.Range (0, 180), Random.Range (0, 180), Random.Range (0, 180));
             diceThrowInit = 0;
     }

     void generateDice ()
     {
             diceClone = Instantiate (orignalDice, dicePlayCam.transform.position, Quaternion.Euler (Random.Range (0, 180), Random.Range (0, 180), Random.Range (0, 180))) as GameObject;    
     }
 #region Coroutines

     IEnumerator getDiceCount ()
     {
             //Time.timeScale = 1.3f;    
             currentCampPos = dicePlayCam.transform.position;
             //wait fore dice to stop...
             yield return new WaitForSeconds (1.0f);
             while (diceClone.GetComponent<Rigidbody>().velocity.magnitude > 0.05f) {
                     yield return 0;
             }

             Time.timeScale = 0.2f;
             timeRate = 0.001f;
             float startTime = Time.time;
             Vector3 risePos = dicePlayCam.transform.position;
             Vector3 setPos = new Vector3 (diceCarrom.position.x, diceClone.transform.position.y + 25f, diceCarrom.position.z);
             float speed = 0.18f;
             float fracComplete = 0;

             while (Vector3.Distance(dicePlayCam.transform.position,setPos)>0.5f) 
             {
                     Vector3 center = (risePos + setPos) * 0.5f;
                     center -= new Vector3 (0, 2, -1);
                     Vector3 riseRelCenter = risePos - center;
                     Vector3 setRelCenter = setPos - center;
             
                     if (fracComplete > 0.85f && fracComplete < 1f) {
                             speed += Time.deltaTime * 0.3f;
                             Time.timeScale -= Time.deltaTime * 4f;
                     } 
                     dicePlayCam.transform.position = Vector3.Slerp (riseRelCenter, setRelCenter, fracComplete);
                     dicePlayCam.transform.position += center;
                     dicePlayCam.transform.LookAt (diceCarrom);
                     fracComplete = (Time.time - startTime) / speed;
                     yield return 0;
             }

             Time.timeScale = 1.0f;
             Dice.Instance.GetDiceCount();
             gui.text = "Dice Count : " + Dice.Instance.GetDiceCount();
             yield return new WaitForSeconds (5f);

             Dice.Instance.diceCount = 0;
             Dice.Instance.GetDiceCount ();
             diceCount = Dice.Instance.GetDiceCount ();
             gui.text = "Dice Count : " + diceCount;
             diceClone.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.None;
             Application.LoadLevel(0);
     }

 #endregion

}

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by LoBlanc · Dec 13, 2016 at 10:26 AM

A way to find out what's failing could be surrounding the parse instructions (which throw exceptions) with a try / catch block. Then you can capture the exception and analyse it to see what's wrong.

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

87 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 avatar image avatar image

Related Questions

How to detect non-latin letters? 1 Answer

JSON value contains "instanceID" 0 Answers

inputString returns blank for non-char keys 0 Answers

FormatException: Input string was not in the correct format System 0 Answers

Input.inputString and Input.GetKeyDown do nothing 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