Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Help with character creation

Discussion in 'Scripting' started by DroneNz, Jun 3, 2023.

  1. DroneNz

    DroneNz

    Joined:
    Oct 4, 2022
    Posts:
    15
    So here is my problem, i'm creating a "voxel" game, and i'm stuck in a problem about changing different textures in the same body part, more specifically with the head, i want to change hair, skin and eye colors, here are the solutions i tought and tested at some level

    1-creating a texture for every combination possible and using math to create the ilusion that only one is changing(i prefer not having customization at all than doing this lol

    2-using the multi material feature on skined mesh renderer, it works, but something looks silly about it

    i just want a direction, how i accomplish that?, i also tought about spliting my head mesh, but my head mesh is a essentialy a cube, the face is flat so i dont that would work
     
  2. Lekret

    Lekret

    Joined:
    Sep 10, 2020
    Posts:
    272
    How does your material looks like?
    If you have single material that have different color fields for hair, skin etc. then you can change specific color from code.
    If you have multiple materials, then you can change their main color from code.
    Why not doing this?
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,749
    These are all valid ways, each with different tradeoffs. For instance making separate prefabs for each variation may be preferred if you have a large team working on a game. Simply trading out a texture or material may be more suitable for you.

    Whatever you choose, it is FAR MORE IMPORTANT that you choose and move forward and learn. If it works, it works. If you have to change, then you have already learned and can change faster and better.

    Just for full disclosure, keep this in mind:

    These things (inventory, shop systems, character customization, dialog tree systems, crafting, etc) are fairly tricky hairy beasts, definitely deep in advanced coding territory.

    Inventory code never lives "all by itself." All inventory code is EXTREMELY tightly bound to prefabs and/or assets used to display and present and control the inventory. Problems and solutions must consider both code and assets as well as scene / prefab setup and connectivity.

    Inventories / shop systems / character selectors all contain elements of:

    - a database of items that you may possibly possess / equip
    - a database of the items that you actually possess / equip currently
    - perhaps another database of your "storage" area at home base?
    - persistence of this information to storage between game runs
    - presentation of the inventory to the user (may have to scale and grow, overlay parts, clothing, etc)
    - interaction with items in the inventory or on the character or in the home base storage area
    - interaction with the world to get items in and out
    - dependence on asset definition (images, etc.) for presentation

    Just the design choices of such a system can have a lot of complicating confounding issues, such as:

    - can you have multiple items? Is there a limit?
    - if there is an item limit, what is it? Total count? Weight? Size? Something else?
    - are those items shown individually or do they stack?
    - are coins / gems stacked but other stuff isn't stacked?
    - do items have detailed data shown (durability, rarity, damage, etc.)?
    - can users combine items to make new items? How? Limits? Results? Messages of success/failure?
    - can users substantially modify items with other things like spells, gems, sockets, etc.?
    - does a worn-out item (shovel) become something else (like a stick) when the item wears out fully?
    - etc.

    Your best bet is probably to write down exactly what you want feature-wise. It may be useful to get very familiar with an existing game so you have an actual example of each feature in action.

    Once you have decided a baseline design, fully work through two or three different inventory tutorials on Youtube, perhaps even for the game example you have chosen above.

    Breaking down a large problem such as inventory:

    https://forum.unity.com/threads/weapon-inventory-and-how-to-script-weapons.1046236/#post-6769558

    If you want to see most of the steps involved, make a "micro inventory" in your game, something whereby the player can have (or not have) a single item, and display that item in the UI, and let the user select that item and do things with it (take, drop, use, wear, eat, sell, buy, etc.).

    Everything you learn doing that "micro inventory" of one item will apply when you have any larger more complex inventory, and it will give you a feel for what you are dealing with.

    Breaking down large problems in general:

    https://forum.unity.com/threads/opt...n-an-asteroid-belt-game.1395319/#post-8781697
     
  4. DroneNz

    DroneNz

    Joined:
    Oct 4, 2022
    Posts:
    15
    this is my current head texture, its from the ape race that i'm working, and the head head.png
    And here is the model itself:
    upload_2023-6-3_13-1-46.png
     
  5. Lekret

    Lekret

    Joined:
    Sep 10, 2020
    Posts:
    272
    On your character GameObject you probably have MeshRenderer which have different materials.
    From seeing your setup I guess you are probably created model and texture yourself and using default material.

    The easiest way to solve your problem would be using a couple of different materials. I'm not an artist, but some models support different materials for different parts of the same model. Because Renderers have array of materials, exactly for many of them.
    Again, I'm not an artist and don't know what you are using, but even if I did, I can't really help you with artist part.
    I would recommend you digging through tutorials how to make model with different materials.
    Then you can have one model with different materials, so you can access specific one from code.
    https://docs.unity3d.com/ScriptReference/Renderer.html
    https://docs.unity3d.com/ScriptReference/Material.html
     
    DroneNz and Kurt-Dekker like this.