- Home /
 
 
               Question by 
               AshwinTheGammer · Jul 05, 2021 at 08:36 AM · 
                uiquaterniondamageindicatorhealth  
              
 
              Damage Indicator not showing correct position of attack.
So, I'm trying to convert GUI into UI. Since, the code was originally written for GUI.
My problems are: The Alpha value of DamageIndicator isn't decreasing to 0.
It doesn't show correct Position of Attack.
Here's the script:
 public RawImage hitIndicatorUI;
 public bool damageIndicator = true;
 public int maxIndicators = 5;
 private List<DamageIndicator> indicatorList = new List<DamageIndicator>();
 
  private void Update(){
         for (int i = 0; i < indicatorList.Count; i++)
         {
             if (indicatorList[i].indicatorAlpha > 0)
             {
                 CalculateDamageIndicatorAngle(indicatorList[i]);
                 indicatorList[i].indicatorAlpha -= Time.deltaTime;
             }
             else{
              indicatorList.RemoveAt(i); } } }
   private void OnGUI()
 {    ShowUIDamageScreen();}
 private void ShowUIDamageScreen()
     {
  //Original GUI script.
 
 /*    for (int i = 0; i < indicatorList.Count; i++)
         {
             GUI.color = new Color(1, 0, 0, indicatorList[i].indicatorAlpha);
             GUIUtility.RotateAroundPivot(indicatorList[i].indicatorAngle, new Vector2((Screen.width / 2), (Screen.height / 2)));
             GUI.DrawTexture(new Rect(Screen.width / 2 - size / 2, Screen.height / 2 - size * radius, size, size), hitIndicator);
             GUIUtility.RotateAroundPivot(0 - indicatorList[i].indicatorAngle, new Vector2((Screen.width / 2), (Screen.height / 2)));
         }
 
         GUI.color = new Color(1, 1, 1, 1);
         */
 
         for (int i = 0; i < indicatorList.Count; i++)
         {
             
             hitIndicatorUI.color = new Color(hitIndicatorUI.color.r, 0, 0, indicatorList[i].indicatorAlpha);
             hitIndicatorUI.rectTransform.rotation = Quaternion.Euler(hitIndicatorUI.rectTransform.eulerAngles.x, hitIndicatorUI.rectTransform.eulerAngles.y, -(indicatorList[i].indicatorAngle));
             hitIndicatorUI.rectTransform.rotation = Quaternion.Euler(hitIndicatorUI.rectTransform.eulerAngles.x, hitIndicatorUI.rectTransform.eulerAngles.y, -(0 - indicatorList[i].indicatorAngle));
         }
         hitIndicatorUI.color = new Color(hitIndicatorUI.color.r, hitIndicatorUI.color.g, hitIndicatorUI.color.b, 1f);
     }
 
     private void CalculateDamageIndicatorAngle(DamageIndicator d)
     {
         Vector3 lhs = playerCamera.transform.forward;
 
         Vector3 rhs = d.damageDir - transform.position;
         rhs.y = 0;
         rhs.Normalize();
 
         d.indicatorAngle = Vector3.Cross(lhs, rhs).y > 0 ? (1 - Vector3.Dot(lhs, rhs)) * 90 : (1 - Vector3.Dot(lhs, rhs)) * -90;
     }
 
              
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Health DMG 5x gameobject 0 Answers
Colliders, Triggers, Damage, and Fire 2 Answers
Why Wont My AI Deal Damage To My FPS On Collision 0 Answers
My Photon health script doesnt work 2 Answers