Note Note: If you are just assigning the healthRect Gameobject in the inspector and only using it to get it's RectTransform component then you can delete this variable and just assign the healthRectTransform field in the inspector and skip out the part in the Start method. net), that is the kind of color change/range I am trying to achieve (rather than just basic/primary color changes). If I change the 'Hue' of the image in my graphics program (paint. Hi, I am trying to make a sort of health bar with a slider from the new UI system. lor Color.Lerp( Color.red, een, slider1.value / 100) JugglingJoe, 5 sivaavis611 and blutcat like this. HealthRectTransform.SetInsetAndSizeFromParentEdge(, 0, sliderSize) ĭoing it this way means that you only have to call GetComponent once in the Start function which is far more efficient. We will make updates to use DOTween to change the Fill Amount of the image. Hi all, Still very much a beginner and am trying to allow the player to change the color of a UI image using a slider. HealthRectTransform = healthRect.GetComponent() Private RectTransform healthRectTransform Hi all, Still very much a beginner and am trying to allow the player to change the color of a UI image using a slider. I think the problem is either with if statements or with the public void code. Changing lights is useful if you want to create ambience and immersive UIs. When I hit play to see if it works the first color, Colors0, shows as its suppose to but changing the slider value doesnt change the color. In fact, we can change everything that has a color, including lights. Note: calling GetComponent in the update function is inefficient you should cache a reference to the RectTransform at Start and then use that like so: public Slider healthSlider Trying to change the color of UI images using a single slider and so far have 3 script attempts but none of the results are quite right. When the value of the slider reaches the next set of ranged numbers I want the color to change to the color for that range. The second parameter lets you position where the left side of the slider should be relative to it's parent. This will keep the slider alligned to the left while 'scaling' it out to the right. HealthRect.GetComponent ().SetInsetAndSizeFromParentEdge(, 0, sliderSize) Your code might look like this: public Slider healthSlider Try and use the RectTransform's SetInsetAndSizeFromParentEdge method.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |