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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Change sprite Prefab?

Discussion in 'Scripting' started by hellpirat, Sep 9, 2015.

  1. hellpirat

    hellpirat

    Joined:
    Jun 12, 2015
    Posts:
    26
    Hello.
    I have problems with prefab on android.
    I have prefab - Player. When I change him sprite - it does not change, but in Unity Editor everything ok.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,808
    You're going to probably have to post some code before anyone can help you. Be sure to review Code Formatting Guidelines for this forum or else your code will be unreadable and again nobody will be able to help you.
     
  3. hellpirat

    hellpirat

    Joined:
    Jun 12, 2015
    Posts:
    26
    Code (CSharp):
    1. public GameObject Player;
    2.  
    3. if (num == i && Itemses[i].Price == 0)
    4.             {
    5.                 for (var j = 0; j < Itemses.Count; j++)
    6.                 {
    7.                     Itemses[j].ActiveRocket.SetActive(false);
    8.                     Itemses[j].IsActive = false;
    9.                 }
    10.                 Itemses[i].IsActive = true;
    11.                 Itemses[i].ActiveRocket.SetActive(true);
    12.                 Player.GetComponent<SpriteRenderer>().sprite = Itemses[i].Prefabs.GetComponent<Image>().sprite;
    13.             }
    a small piece of code
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,808
    Do you dynamically load the .Prefabs field of the Itemses chunks? This can fail if you don't put your files int he right place.

    Have you debugged the steps of this to ensure what you think is happening is actually happening, such as the first condition on line 3 actually firing?

    What about inserting some debug log outputs at various places to tell you some more info when running on the device and watching the device log?
     
  5. hellpirat

    hellpirat

    Joined:
    Jun 12, 2015
    Posts:
    26
    Thanks, but I find a solution. The problem was in an object on the scene.
    I have 2 scene with the object Player, But now I use prefab.