Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

load sprite on android platform

Discussion in '2D' started by aryiaDehbozorgi, Jan 20, 2021.

  1. aryiaDehbozorgi

    aryiaDehbozorgi

    Joined:
    Jan 7, 2021
    Posts:
    6
    hi

    my platform is android and load sprite >>> s2 = Resources.Load<Sprite>("test" + level.text);

    but after make apk file and install on phone not work

    How is addressing file in resource folder for Android ? :)
     
  2. ayman_mahtala

    ayman_mahtala

    Joined:
    Sep 5, 2019
    Posts:
    3
    You should provide more information, like:

    - What datatype is the s2 variable?
    - Exactly what does not work?
    - Does it work in the Editor?
    - Perhaps a code snippet explaining the situation better.

    It's really hard to help with such a low amount of information. I can give the following 'guess'-answers.

    - If you load a sprite through Resources.Load, the resource needs to be in a folder named Resources (read https://docs.unity3d.com/ScriptReference/Resources.Load.html for more info).
    - s2 does not hold a Sprite datatype.

    That's all I can do with the information given.
     
  3. aryiaDehbozorgi

    aryiaDehbozorgi

    Joined:
    Jan 7, 2021
    Posts:
    6
    thank you for answer
    in the editor worked

    my code is :

    Code (CSharp):
    1.   private Sprite s2;
    2.     public Text level;
    3.  
    4.      public Image img2;
    5.    
    6.  
    7.     void Start()
    8.     {
    9.         load_image_question();
    10.  
    11.  
    12.     }
    13.  
    14.  
    15.  
    16.     public void load_image_question()
    17.     {
    18.  
    19.         img2.GetComponent<SpriteRenderer>();
    20.  
    21.         s2 = Resources.Load<Sprite>(image.png);
    22.  
    23.        
    24.  
    25.         img2.GetComponent<Image>().sprite = s2;
    26.  
    27.    
    28.  
    29.     }
     
  4. ayman_mahtala

    ayman_mahtala

    Joined:
    Sep 5, 2019
    Posts:
    3
    It's impossible for this to work in the editor because of line 21:

    s2 = Resources.Load<Sprite>(image.png);

    There needs to be quotation marks around "image.png", because the path to the resources is a string.

    Also, if the asset is in a folder within Resources, the full path to the asset needs to be specified.
     
  5. aryiaDehbozorgi

    aryiaDehbozorgi

    Joined:
    Jan 7, 2021
    Posts:
    6
    Thanks for answering

    Please give a complete example of a complete asset path for the Android platform, such as reading a photo or text file .
    In line s2 = Resources.Load<Sprite>("imag1");
    My path is string but after make apk and install the phone don't work .... Plz help