Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Need help with Character Customisation Script [C#]

Discussion in 'Scripting' started by Iceking688, Jan 14, 2017.

  1. Iceking688

    Iceking688

    Joined:
    Jan 14, 2017
    Posts:
    4
    Specifically with hair.

    I want a function that toggles between different hair styles, right now I can only toggle between bald (which isn't even an option I want to have) and the first of the hair styles. How would I go about making the other hair styles visible?

    Here is the code I have for the function.

    private void NextHair(List<CIhair> hair)
    {
    pri_selected_hair_mesh++;
    foreach (CIhair item in hair)
    {
    item.isVisible = false;
    if (pri_selected_hair_mesh > MAX_HAIR_MESHES - 1)
    {
    pri_selected_hair_mesh = hair.IndexOf(item);
    item.isVisible = true;
    }
    }
    Debug.Log("Selected hair mesh: " + pri_selected_hair_mesh);
    }
     
  2. BubyMB

    BubyMB

    Joined:
    Jun 6, 2016
    Posts:
    140
    Instead of setting the item as visible, make them into a prefab and instantiate them when you need them. Instead of having a List, make an Array, and also make an int of the current Selected hairstyle. whenever the button is pressed currentHairStyle++ (or --) and instantiate the current Hairstyle and remove the currentHairStyle - 1.
    This would be the way I would do it.
    And since you don't want bald, on Start(). set currentHairStyle to 0, and instantiate HairStyle 0
     
  3. Iceking688

    Iceking688

    Joined:
    Jan 14, 2017
    Posts:
    4
    I don't think this will work with what I'm using, as my model is one of the Morph 3D character models.
     
  4. iamsidv

    iamsidv

    Joined:
    Jan 24, 2013
    Posts:
    17
    Hi, can you give a little more insights in this?