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 mfarrell806 · Jan 04, 2017 at 02:58 PM · uiinputscript.link

Link UI Input Field to Script

The Script in question is this one:`using UnityEngine; using System.Collections;

public class GoogleMap : MonoBehaviour { public enum MapType %|-1957000663_2|% RoadMap, Satellite, Terrain, Hybrid %|-632995662_7|% public bool loadOnStart = true; %|-1464234556_9|% public GoogleMapLocation centerLocation; public int zoom = 13; %|-1414845350_12|% public int size = 512; public bool doubleResolution = false; public GoogleMapMarker[] markers; public GoogleMapPath[] paths;

%|1077180128_17|% { if (loadOnStart) Refresh(); %|1841942021_20|%

 public void Refresh()
 {
     if (autoLocateCenter && (markers.Length == 0 && paths.Length == 0))

%|-122252710_24|% %|-1704368595_25|% } %|-2091729669_27|% }

%|-1002132817_29|% { %|1805603506_31|% %|1791570299_32|% %|-777112843_33|% %|-1967131424_34|% %|-1189092094_35|% %|543796066_36|% else { qs += "center=" + WWW.UnEscapeURL(string.Format("{0},{1}", centerLocation.latitude, centerLocation.longitude)); }

         qs += "&zoom=" + zoom.ToString();
     }
     qs += "&size=" + WWW.UnEscapeURL(string.Format("{0}x{0}", size));
     qs += "&scale=" + (doubleResolution ? "2" : "1");
     qs += "&maptype=" + mapType.ToString().ToLower();
     var usingSensor = false;

if UNITY_IPHONE

    usingSensor = Input.location.isEnabledByUser && Input.location.status == LocationServiceStatus.Running;

endif

|2136518741_48|%

     foreach (var i in markers)
     {
         qs += "&markers=" + string.Format("size:{0}|color:{1}|label:{2}", i.size.ToString().ToLower(), i.color, i.label);
         foreach (var loc in i.locations)

%|-1310872866_53|% if (loc.address != "") %|-1553893620_55|% %|966862394_56|% %|2012631069_57|% %|-1709193653_58|% }

%|-126405656_60|% { %|202957784_62|% %|1969094223_63|% %|-595190589_64|% { if (loc.address != "") qs += "|" + WWW.UnEscapeURL(loc.address); else %|-1988163170_69|% %|-1309563583_70|% %|30247691_71|%

     var req = new WWW(url + "?" + qs);

%|1900091126_73|% %|697756430_74|% %|-738730212_75|%

}

public enum GoogleMapColor { black, %|-1366980874_77|% %|-482055578_78|% purple, yellow, %|137787309_81|% gray, orange, %|-1282336543_84|% white }

[System.Serializable] public class GoogleMapLocation { %|-1729647901_86|% %|538392101_87|% public float longitude; }

[System.Serializable] public class GoogleMapMarker { public enum GoogleMapMarkerSize { Tiny, %|-244782460_92|% Mid } public GoogleMapMarkerSize size; public GoogleMapColor color; %|614298737_97|% %|-552143230_98|%

}

[System.Serializable] public class GoogleMapPath { public int weight = 5; public GoogleMapColor color; public bool fill = false; public GoogleMapColor fillColor; public GoogleMapLocation[] locations; }

What I want to do is provide an Input Field that will allow the user to enter the Latitude and Longitude values for Map Center in a UI Input field.

So far nothing I have tried does what is desired. I want the user to be able to enter and update map after filling in Latitude and Longitude values.alt text`

googlemap.jpg (38.9 kB)
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 Creeper_Math · Jan 04, 2017 at 08:41 PM 0
Share

Are you able to give JUST the base code without formatting changes?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Creeper_Math · Jan 04, 2017 at 08:54 PM

This requires adding a reference to two UI text fields (which should be set to Int input). Below is the script that would work

 // Add to using
 using UnityEngine.UI;
 
 // Add to variables
 public InputField Longitude;
 public InputField Latitude;
 
 
 
 // Add this to the Start function if u have any
 Longitude.onValueChanged.AddListener (delegate {UpdateLocation();});
 Latitude.onValueChanged.AddListener (delegate {UpdateLocation();});
 
 // Add this function for updating the variables
 void UpdateLocation() {
       float.TryParse(Longitude.text, out CenterLocation.Longitude);
       float.TryParse(Longitude.text, out CenterLocation.Latitude);
 }
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 mfarrell806 · Jan 04, 2017 at 10:34 PM

Thanks for the above, easy enough to figure out where the USING stuff goes,

However being new and confused...not sure where I would put the stuff for Variables, as the only ones I see and recognize are in the CoRoutine _Refresh

So where would I insert the other portions of the code provided?

It's interesting to note that I have seen others post similar question; and no one other than yourself has provide any usable answer.

So you will be helping quite a few with these answers,

Thanks in advance!

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 Creeper_Math · Jan 04, 2017 at 11:06 PM 0
Share

The Variables would go right after the "$$anonymous$$onobehavior" script, so in your example, they would go with public class Google$$anonymous$$ap : $$anonymous$$onoBehaviour {

The second set of code would go under a new void (as you don't have a Start() ). Since you don't have one, then just add this into your code at any part inside the monobehavior, as well as the update locations.. Put the following snippet as a new void

 void Start() {
       Longitude.onValueChanged.AddListener (delegate {UpdateLocation();});
       Latitude.onValueChanged.AddListener (delegate {UpdateLocation();});
 }
 void UpdateLocation() {
        float.TryParse(Longitude.text, out CenterLocation.Longitude);
        float.TryParse(Longitude.text, out CenterLocation.Latitude);
  }

Also, for further unity answers, for this type of response, please put it as a "comment" under my answer ins$$anonymous$$d of a separate answer

avatar image mfarrell806 · Jan 05, 2017 at 02:14 PM 0
Share

There is a start, although it looks like I don't due to how the website posted my code.

Let me try again...meanwhile I see what happens if I put those lines within the current start statement.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class Google$$anonymous$$ap : $$anonymous$$onoBehaviour
 {
     public enum $$anonymous$$apType
     {
         Road$$anonymous$$ap,
         Satellite,
         Terrain,
         Hybrid
     }
     public bool loadOnStart = true;
     public bool autoLocateCenter = true;
     public Google$$anonymous$$apLocation centerLocation;
     public int zoom = 13;
     public $$anonymous$$apType mapType;
     public int size = 512;
     public bool doubleResolution = false;
     public Google$$anonymous$$ap$$anonymous$$arker[] markers;
     public Google$$anonymous$$apPath[] paths;
     public InputField Longitude;
     public InputField Latitude;
 
 
 
     void Start()
     {
         if (loadOnStart) Refresh();
             }
 
     public void Refresh()
     {
         if (autoLocateCenter && (markers.Length == 0 && paths.Length == 0))
         {
             Debug.LogError("Auto Center will only work if paths or markers are used.");
         }
         
avatar image mfarrell806 · Jan 05, 2017 at 04:57 PM 0
Share

Obviously where I inserted them is the wrong place or method, Upon adding those lines within Start() function I now get this error

NullReferenceException: Object reference not set to an instance of an object

Google$$anonymous$$ap.Start () (at Assets/Standard Assets/Scripts/Google$$anonymous$$ap.cs:31)
avatar image hdtnl mfarrell806 · Jan 05, 2017 at 05:05 PM 0
Share

i think you should check: markers.Length == 0 && paths.Length == 0

avatar image mfarrell806 hdtnl · Jan 05, 2017 at 05:11 PM 0
Share

O$$anonymous$$, what would I be checking for?

I ask out of ignorance. Because the script worked before, although I really wanted to give the user input fields to enter their actual location or any global location during game play. Thus my request for the ability to properly link two input fields to the Latitude and Longitude that the Google $$anonymous$$ap script uses.

So, what would I set them to, and if you know where would I place the

 Longitude.onValueChanged.AddListener (delegate {UpdateLocation();});
        Latitude.onValueChanged.AddListener (delegate {UpdateLocation();});
  }
  void UpdateLocation() {
         float.TryParse(Longitude.text, out CenterLocation.Longitude);
         float.TryParse(Longitude.text, out CenterLocation.Latitude);
   }

Within the script that I have?

Thanks!

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

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

Related Questions

How do I disable player input action map and enable the UI action map? 4 Answers

How to change a float value with UI buttons,How Can I control a character with UI buttons? 1 Answer

Optimal way to display a player's health with hearths? 1 Answer

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

Why when using a ui button script with ui toggle to interact with another script it's not working good ? 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