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

"The name 'Convert' does not exist in the current context" C#

I am trying to use Input Field boxes for multiplying the given input from the user. I need to change the string into an integer form so i can multiply it, then i need change it back to a string once it is multiplied so the answer can be displayed. (or at least i think that's how it should work)

I have 2 questions, How can i fix this error: Assets/Calculations.cs(20,25): error CS0103: The name `Convert' does not exist in the current context

and 2, how can i call from my own Input Field boxes instead of what i have in the example script? The script i have is a very rough idea of what i need to do.

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class Calculations : MonoBehaviour {
 
     public InputField Field1;
     public InputField Field2;
     public Text Result;
     
 //    public void Sum() {
 //        int a = Convert.ToInt32(Field1.text);
 //        int b = Convert.ToInt32(Field2.text);
 //        int c = a+b;
 //        Result.text = c.ToString();
 //    }
     
     
     public void Product() {
         int a = Convert.ToInt32(Field1.text);
         int b = Convert.ToInt32(Field2.text);
         int c = a*b;
         Result.text = c.ToString();
     }
     
 }

 
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
5
Best Answer

Answer by Addyarb · Mar 27, 2015 at 05:51 AM

As the other answer reads, put

 using System;

At the top.

You did well with using UnityEngine.UI;

In order to get your text fields' data in, try this:

 //Top of the script
 
 public GameObject textField_1;
 public GameObject textField_2; //drag these game objects into the script via the inspector.
 InputField t1;
 InputField t2;
 
 void Start()
 {
 t1 = textField_1.GetComponent<InputField>();
 t1 = textField_2.GetComponent<InputField>();
 }
 
      public void Product() {
          int a = Convert.ToInt32(t1.text);
          int b = Convert.ToInt32(t2.text);
          int c = a*b;
          Result.text = c.ToString();
      }


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 Ian-McCleary · Mar 28, 2015 at 12:56 AM 0
Share

So far your code works, except now it says it doesnt recognize "Result" in the current context. any ideas?

avatar image Ian-McCleary · Mar 28, 2015 at 01:01 AM 0
Share

Sorry, never $$anonymous$$d i found a typo. Thank you for the help!!!

avatar image
1

Answer by HarshadK · Mar 27, 2015 at 05:43 AM

Convert exists in System namespace so you either have to call it using:

 System.Convert.ToInt32

or import the namespace with:

 using System;

at the top.

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

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

Help I am getting an error CS0079 in my code and I don't know why. 1 Answer

Particle circle HELP 1 Answer

Trouble converting player controller from JS to C# 1 Answer

How Converting GUILayout.TextField with UI InputField ? 2 Answers

How can I make a new line in Unity UI text? 2 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