Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Help to create health using array for each parts of the model in single script

Discussion in 'Scripting' started by pauloaguiar, May 2, 2019.

  1. pauloaguiar

    pauloaguiar

    Joined:
    May 13, 2009
    Posts:
    700
    Help to create health using array for each parts of the model in single script

    I do not even know where to start, so I searched the net if there was anything to show me the way.
    The goal is to create a health script for various parts of the 3d model, whose purpose each part of the model loses its health.
    Basically that's all, that's what I need. And of course, if it is possible to do so.

    So far....

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class damagePartsList : MonoBehaviour
    6. {
    7.     public GameObject[] parts;
    8.     //public int negativeHP = 15;
    9.     public int[] standarHP = new int[5];
    10.  
    11.     // Start is called before the first frame update
    12.     void Start()
    13.     {      
    14.     }
    15.     // Update is called once per frame
    16.     void FixedUpdate()
    17.     {      
    18.     }
    19.  
    20.     void OnCollisionEnter(Collision collision)
    21.     {
    22.         //StandarHpHealth();
    23.  
    24.         for (int i = 0; i < 4; i++)
    25.         {
    26.            
    27.         }
    28.  
    29.     }
    30.  
    31.     /*void StandarHpHealth ()
    32.     {
    33.         standarHP[0]--;
    34.  
    35.         if (standarHP[0] < 0 )
    36.         {
    37.             standarHP[0] = 0;
    38.         }      
    39.     }*/
    40. }
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,519
    Looks like you're well on the way. If you get lost, stop, make a script to track health on a single GameObject, then look what you did and go to the one above.

    However, I would actually recommend making a single-GameObject health script (nice and simple) and put separate copies of it on different parts of your model, each with the right amount of health for that part. Way simpler and easier to maintain.
     
    pauloaguiar likes this.
  3. pauloaguiar

    pauloaguiar

    Joined:
    May 13, 2009
    Posts:
    700
    Tks , i will try :)