Scale gameobject on just one side

后端 未结 2 785
予麋鹿
予麋鹿 2020-12-10 21:59

I have added Cube to scene and I scaled and put to position ( 0, 0, 0 ). I am scaling that Cube with code attached to Cube

IEnumerator Start() {
    StartCor         


        
2条回答
  •  被撕碎了的回忆
    2020-12-10 22:37

    You can use Slider for the purpose. I was designing a Loading bar for which I needed to Increase width of the loader according to the download that is progressed. You can disable its handle, and use custom Sprite for loading fill percentage. You can also use custom Sprite for background. To use Slider, go to Menu Bar -> GameObject -> UI -> Slider. Or instead You can Add a Slider Component from the Inspector for the GmaeObject you want (Select the GameObject you want to add Slider -> In the Inspector click Add Component -> UI -> Slider. Now Set Fill Rect and other Options). You can set Slider from Left to Right, Right to Left, Bottom to Top, or Top to Bottom.

    In the Script

    using UnityEngine.UI;
    public class SliderExample : MonoBehaviour
    {
        public Slider slider;  // Drag and Drop Slider GameObject in Unity Inspector
        float percentageCompleted;
    
        void Update()
        {
            slider.value = percentageCompleted;  
            // specify percentage Completed, if required Divide by 100 as Slider values are from 0 to 1 or set Max Value in Inspector as 100
        }
    }
    

    You can also watch this Brackeys video for some help regarding setting up the Slider "https://www.youtube.com/watch?v=YMj2qPq9CP8".

提交回复
热议问题