Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Ian-McCleary · Apr 27, 2015 at 04:38 AM · c#errorbuttonfunctiondebug

Button not executing function. C#

I have a button that i would like to call a specific math function with. I placed Debug.Log messages to test what was going on. It appears that The button is not even calling the function because when i click it, the very first debug.log(3) for that function doesn't show up in the console.

Here is a screen shot and my script. I feel like i may have setup the script incorrectly because i am a newbie, but it should still call the Debug.Log(3) right?

I get Debugs 1 and 2 but not 3. I commented out the rest of my math function to test. Screenshot at bottom. using UnityEngine; using UnityEngine.UI; using System.Collections; using System;

 public class Calculations : MonoBehaviour {
     
     public GameObject textField_1;
     public GameObject textField_2;
     public GameObject textField_3;
     public Text Result;
     InputField t1;
     InputField t2;
     InputField t3;
 
     void Start()
     {
         Debug.Log (1);
         t1 = textField_1.GetComponent<InputField> ();
         t2 = textField_2.GetComponent<InputField> ();
         t3 = textField_3.GetComponent<InputField> ();
         Debug.Log (2);
     }
 
     
     public void Product() {
         Debug.Log (3);
         double a = Convert.ToDouble(t1.text);
         double b = Convert.ToDouble(t2.text);
         double c = Convert.ToDouble(t3.text);
         double d = a / 2;
         //double e = d * d;
         //double f = (e * 3.14) / b;
         Result.text = d.ToString ();
     }
     
 }

alt text

UPDATE: I just created a new button and applied the calculations script to it and added everything in the inspector. I get the Debug.log(3) but I also get an error. Here it is

FormatException: Unknown char: r System.Double.Parse (System.String s, NumberStyles style, IFormatProvider provider) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/Double.cs:209) System.Double.Parse (System.String s) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/Double.cs:180) System.Convert.ToDouble (System.String value) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/Convert.cs:983) Calculations.Product () (at Assets/Script/Calculations.cs:28) UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:110) UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:574) UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:716) UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:53) UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35) UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44) UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:52) UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:269) UnityEngine.EventSystems.EventSystem:Update()

Is there something wrong with my function? Why doesnt my other button do this?

Thanks in advance for help!!!

inspector.png (74.9 kB)
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

3 Replies

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

Answer by Ian-McCleary · Apr 28, 2015 at 03:55 AM

So i figured out that there was most likely a scripting error on my part. I reverted back to an old version and everything is working again even though that part stays almost the exact same. I dont need help anymore and thanks to those who did!

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 Hrungdak · Apr 27, 2015 at 05:07 AM

Seems like your input value to the Convert.ToDouble-Method is wrong.

You can use TryParse to avoid this:

 double a = 0;
 if (!double.TryParse(t1.text, out a))
     // t1.text can not be converted to double
 
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 Noob_Vulcan · Apr 27, 2015 at 05:17 AM

Looks like that the problem is with your Text Fields ...

Make sure that you Text Fields have Numeric input.

  double a = Convert.ToDouble("any_string");   //Wrong .. 
 
 
 
  double a = Convert.ToDouble(9857);     //Right
 or
  double a = Convert.ToDouble("3423");    //Right
Comment
Add comment · Show 5 · 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 Ian-McCleary · Apr 28, 2015 at 01:59 AM 0
Share

Are those random numbers you put in there? or do they have to be specific?

avatar image Noob_Vulcan · Apr 28, 2015 at 02:01 AM 0
Share

Any random number..... Just dont but any alphabetical alphabetical character

avatar image Ian-McCleary · Apr 28, 2015 at 02:10 AM 0
Share

Then how is it supposed to realize i want the numbers from the text boxes/input fields? It just used the numbers i put in the parentheses

avatar image Noob_Vulcan · Apr 28, 2015 at 02:49 AM 0
Share

Use Convert.ToDouble(t1.text)

Input a number in text box

avatar image Ian-McCleary · Apr 28, 2015 at 03:53 AM 0
Share

haha yes i realize this, but it wasn't working. I reverted back to an old version of my script and caught myself up. I think that there was some sort of error that i was unaware of going on because the old version doesn't change at all in that section. Thanks for the help anyway!

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

21 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

Related Questions

Import Componet ( Variable ) Error Unexpected Token 3 Answers

C# script failing silently? 0 Answers

GooglePlayServices & GoogleMobileAds 0 Answers

How to get the colliders working? 1 Answer

Photon RPC "DestroyRpc" function not found 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