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 refsus · Aug 26, 2013 at 04:40 AM · textureconnectionurl

Check if connected to internet or not

I had a small study, in which I took a picture from the internet url and then convert into an image file. The picture attached to a plane as a texture. If I have a connection to the internet, all went smoothly, but when I do not have an internet connection, there is an error that the data retrieval error. I want to ask is how to check whether I am connected to the internet or not, if yes I took the url on the internet and turn it into a texture, if not, I take a byte of data from local and insert it into a texture. I will attach a simple code ..

 using UnityEngine;
 using System.Collections;
 using System.IO;
 
 public class RetrieveURL : MonoBehaviour
 {
 
     string urlGold1 = "http://commondatastorage.googleapis.com/ingress.com/img/Ingress_logo_512px.png";
     GameObject[] Premium;
 
     string Filename;
     StreamReader reader;
     StreamWriter writer;
 
     void Start()
     {
         Load();
         try
         {
             StartCoroutine(LoadImage());
         }
         catch
         {
 
         }
 
         Premium = GameObject.FindGameObjectsWithTag("Premium");
     }
 
 
     void Update()
     {
 
     }
     IEnumerator LoadImage()
     {
         byte[] bytes;
 
         WWW gd2 = new WWW(urlGold1);
         yield return gd2;
 
         Texture2D gld2 = new Texture2D(256, 256, TextureFormat.DXT1, false);
         bytes = gd2.bytes;
         gld2.LoadImage(bytes);
 
         renderer.material.mainTexture = gld2;
     }
 
     public void Load()
     {
         Filename = Application.persistentDataPath + "/SaveURLGold1.txt";
         if (!File.Exists(Filename))
         {
             Filename = Application.persistentDataPath + "/SaveURLGold1.txt";
             writer = File.CreateText(Filename);
             writer.Write("URL Gold1 |" + urlGold1); writer.WriteLine("");
             writer.Close();
         }
         else
         {
             reader = File.OpenText(Filename);
             string buffer;
 
             buffer = reader.ReadLine();
             string[] token = buffer.Split('|');
             urlGold1 = token[1];
 
         }
     }
 }


Here Image if I have connection to internet alt text

and here is image if i don't have connection to internet alt text

I'm sorry for my bad english, I'm from Indonesia.. thanks :)

connect.png (196.9 kB)
lost connection.png (242.7 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

Answer by kumarc123 · Aug 26, 2013 at 10:04 AM

You can use Application.internetReachability() method to check is network is reachable via carrier, LAN, or unreachable.

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 tonic · Aug 20, 2014 at 12:49 PM

To truly know internet can be reached, there needs to be "captive portal detection". It's a technique also used by operating systems, where you simply do a request to an url which gives a reply with known contents. That helps to know if you're e.g. hitting a public WiFi login page. Just checking Application.internetReachability or doing a Ping doesn't guarantee that internet connection works.

I have made an easy asset called Internet Reachability Verifier and it allows you to use one of the captive portal detection methods maintained by big OS vendors, or your own custom url. It keeps you up-to-date whether you have verified internet access and it works with both desktop and mobile platforms (self-hosted custom method can be used with the web player plugin if you think that's necessary).

More info here: http://j.mp/IRVUN

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 niall1111 · Aug 20, 2014 at 12:59 PM

     IEnumerator LoadImage()
     {
         byte[] bytes;
  
         WWW gd2 = new WWW(urlGold1);
         yield return gd2;
  if ( gd2.error != null ) {
 //There was an error downloading the file, do what you like from here.
 }
 else{
         Texture2D gld2 = new Texture2D(256, 256, TextureFormat.DXT1, false);
         bytes = gd2.bytes;
         gld2.LoadImage(bytes);
  
         renderer.material.mainTexture = gld2;
 }
     }
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

18 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

Related Questions

How to assign texture from url 1 Answer

Assigning UV Map to model at runtime 0 Answers

Best way to determine WWW timeout/404/etc.? 2 Answers

Load texture on disabled GameObject 1 Answer

loading different image links into a list 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