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

rendering the texture depending on the condition

Discussion in 'UGUI & TextMesh Pro' started by DrMrkev, Nov 5, 2015.

  1. DrMrkev

    DrMrkev

    Joined:
    Oct 25, 2015
    Posts:
    19
    Hello everyone, I'm make simple game and I want to do it simple health system.
    There are four health points and if so will restart the level for the price of one life pint.chtěl I need something like this

    if (Hp == 4)
    {
    // Render to texture something called Hp-4 ....
    }

    maybe use a switch but that's not important.

    In short, I need something to render texture in the UI of a certain size in a particular place, it would be best to have the UI only one object (picture) and changed his image.

    btw. csharp use and I want him to have the whole game ... please no java :)

    ps. sorry for bad English, I'm from the Czech Republic and to know C # and English on the 17-year-old boy a bit too much
     
  2. Senshi

    Senshi

    Joined:
    Oct 3, 2010
    Posts:
    557
    Hi there, and welcome to the forum!

    If your English comprehension is good enough, I suggest checking out the official tutorials for the new UI system to give you an idea of its fundamentals.

    For this specific request, you can change the image's texture property, like so:

    Code (CSharp):
    1. public Texture hpTexture1;
    2. public Texture hpTexture2;
    3. public Texture hpTexture3;
    4. public Texture hpTexture4;
    5.  
    6. switch(hp){
    7.     case 1: myImage.texture = hpTexture1;
    8.         break;
    9.     case 2: myImage.texture = hpTexture2;
    10.         break;
    11.     case 3: myImage.texture = hpTexture3;
    12.         break;
    13.     case 4: myImage.texture = hpTexture4;
    14.         break;
    15. }
    To see what kind of properties or functionality a component has, please check out the reference manual.

    And don't worry, your English is fine! The only thing I'll correct though is that Unity's other main language is called UnityScript, often called JavaScript. However, Java is yet another language, though totally unrelated to both Unity and JavaScript.
     
    DrMrkev likes this.
  3. DrMrkev

    DrMrkev

    Joined:
    Oct 25, 2015
    Posts:
    19
    thank you for your quick and concise answer, definitely try it
    btw. you have a great mustache, I always wanted such a
     
  4. Senshi

    Senshi

    Joined:
    Oct 3, 2010
    Posts:
    557
    Ha, thanks! Good luck with your project!