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. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Question How To Get Code To Toggle Of Certain Items When Other Items Are Toggled On

Discussion in 'Scripting' started by DotArt, Jan 7, 2023.

  1. DotArt


    Jun 12, 2021
    hey, so basically i have a character that when you toggle on different parts of outfits for them might overlap for other items you have on at the time.

    At the moment i just have it so in the code it turns off any item that will be overlapping with the item you are toggling on and this is done within the code but im wondering if there was a simpler way of doing it as there is now becoming more and more items and its starting to get a bit messy.

    My first thought was to have an array for each item of clothing and have every item that overlaps with it in this array and then when you toggle that item it turns off all the items in that array, again though with lets say 20 different items this will mean there is 20 arrays in the script just for the overlapping items thing.

    if anyone has any idea a similar way of going about this that would be great thanks

    and if you dont really understand what im trying to say a quick example would be if the character has a watch on and you want to add a jacket the has weird clipping with that watch i would want it to toggle off the watch, this is a simple thing when working with a few items but becomes alot more complex when working with more.

    i also wont need something to check which items overlap i know which ones overlap with each other thats why i thought the array method might be a good one
  2. spiney199


    Feb 11, 2021
    Pretty sure every game under the sun that has had this mechanic defines what zones a particular item of clothing covers. Eg a long-sleeve-shirt covers torso, arms, and wrists. You put on a shirt, it covers up anything else the player is wearing in this category.

    So really the steps are: define clothing zones on your player, and have a way to author this in the inspector (I'd define them with scriptable objects).

    You may need some kind of priority system as well.