Script comprehension

script understanding.
I want to work healthbar, I found this script. it works, the idea is to put 3 red hearts which turn white each collision with the enemy.

using UnityEngine;
using System.Collections;

public class Health : MonoBehaviour {
	
	public int startHealth;
	public int healthPerHeart;
	
	private int maxHealth;
	private int currentHealth;
	
	public Texture[] heartImages;
	public GUITexture heartGUI;
	
	private ArrayList hearts = new ArrayList();
	
	// Spacing:
	public float maxHeartsOnRow;
	private float spacingX;
	private float spacingY;
	
	
	void Start () {
		spacingX = heartGUI.pixelInset.width;
		spacingY = -heartGUI.pixelInset.height;
	
		AddHearts(startHealth/healthPerHeart);
	}
	
	public void AddHearts(int n) {
		for (int i = 0; i <n; i ++) { 
			Transform newHeart = ((GameObject)Instantiate(heartGUI.gameObject,this.transform.position,Quaternion.identity)).transform; // Creates a new heart
			newHeart.parent = transform;
			
			int y = (int)(Mathf.FloorToInt(hearts.Count / maxHeartsOnRow));
			int x = (int)(hearts.Count - y * maxHeartsOnRow);

			newHeart.GetComponent<GUITexture>().pixelInset = new Rect(x * spacingX,y * spacingY,58,58);
			newHeart.GetComponent<GUITexture>().texture = heartImages[0];
			hearts.Add(newHeart);

		}
		maxHealth += n * healthPerHeart;
		currentHealth = maxHealth;
		UpdateHearts();
	}

	
	public void modifyHealth(int amount) {
		currentHealth += amount;
		currentHealth = Mathf.Clamp(currentHealth,0,maxHealth);
		UpdateHearts();
	}

	void UpdateHearts() {
		bool restAreEmpty = false;
		int i =0;
		
		foreach (Transform heart in hearts) {
			
			if (restAreEmpty) {
				heart.guiTexture.texture = heartImages[0]; // heart is empty
			}
			else {
				i += 1; // current iteration
				if (currentHealth >= i * healthPerHeart) {
					heart.guiTexture.texture = heartImages[heartImages.Length-1]; // health of current heart is full
				}
				else {
					int currentHeartHealth = (int)(healthPerHeart - (healthPerHeart * i - currentHealth));
					int healthPerImage = healthPerHeart / heartImages.Length; // how much health is there per image
					int imageIndex = currentHeartHealth / healthPerImage;

					
					if (imageIndex == 0  currentHeartHealth > 0) {
						imageIndex = 1;
					}

					heart.guiTexture.texture = heartImages[imageIndex];
					restAreEmpty = true;
				}
			}
			
		}
	}
}

What’s the question exactly?

I like to modify to script to control when the projectile touch the player the hurt come 75% red and 25 % white

OK. And what’s the problem you encountered when doing that?
You can’t just post what you want and expect someone to do the job for you. No one will.

Basically you achieve this by understanding the code and then modifying it. Have you done any of that?
Can’t understand the code? Which part specifically?
You got stuck modifying it? Stock at what exactly?

Do you have any knowledge of Unity scripting?
Have you done these tutorials: Learn game development w/ Unity | Courses & tutorials in game design, VR, AR, & Real-time 3D | Unity Learn ?

I am a beginner student.
I find a solution thanks :slight_smile: