Search Unity

Question I want to create a progress bar showing player movement from start to finish. with a check point Wha

Discussion in 'Scripting' started by preeyaporn110145l, Jan 18, 2022.

  1. preeyaporn110145l

    preeyaporn110145l

    Joined:
    Dec 10, 2020
    Posts:
    8
    Hello, I want to create a progress bar showing player movement from start to finish. with a check point What should I do in the middle?

    Now I can get the player to the last point but I want to add checkpoints, what should I do?


    Code (CSharp):
    1. public class Progressnar2 : MonoBehaviour
    2. {
    3.     public Transform Player;
    4.     public Transform End;
    5.    
    6.     public Slider slider;
    7.     float maxDistance;
    8.     void Start()
    9.     {
    10.        maxDistance = getDistance();
    11.      
    12.     }
    13.  
    14.     // Update is called once per frame
    15.     void Update()
    16.     {
    17.         if (Player.position.z <= maxDistance && Player.position.z <= End.position.z)
    18.         {                  
    19.             float distance = 1 - (getDistance() / maxDistance) ;
    20.             setProgress(distance);
    21.         }
    22.     }
    23.     float getDistance()
    24.     {
    25.         return Vector3.Distance(Player.position,End.position );
    26.     }
    27.     void setProgress(float p)
    28.     {
    29.         slider.value = p;
    30.     }
    31. }
    e2.JPG
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,740
    Set this aside and do a few checkpoint tutorials until you understand what is involved.

    Bring that knowledge back to this game and integrate!