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

Enabling/Disabling multiple object parts

Discussion in 'Scripting' started by Gordyne, Feb 27, 2016.

  1. Gordyne

    Gordyne

    Joined:
    Feb 22, 2016
    Posts:
    32
    I'm trying to find a way of changing my character's armor(5 different pieces) in game. I've got the animation part right(I guess) but there is another big concern.

    I was reading a thread yesterday and it was said to keep all charaters armor parts in one "Master" Object and only enable the one that the character is wearing.

    I was thinking of doing just that, but I wonder if it can be done and still make the game smooth.

    In this image I have my character and 2 sets of 5 pieces(I plan to have much more), but they are on top of each other righ now, Is there a way I can load my object's parts separately and prevent them from loading at the start of the game?

     
  2. Gordyne

    Gordyne

    Joined:
    Feb 22, 2016
    Posts:
    32
    Ok, I found out how to disable the objects and I'm trying to disable the current chest armor and enable the alternative via script(just to see if can work):

    Code (CSharp):
    1. public class swapping_gear : MonoBehaviour {
    2.  
    3.     // Use this for initialization
    4.     void Start () {
    5.     }
    6.  
    7.     // Update is called once per frame
    8.     void Update () {
    9.  
    10.         var leather_s = GameObject.Find("leather_shoulders");
    11.  
    12.         if (Input.GetKeyDown(KeyCode.I)){
    13.             leather_s.SetActive(false);
    14.             leather_s = GameObject.Find("metal_shoulders");
    15.             leather_s.SetActive(true);
    16.         };
    I'm having 2 problems with this:

    1 - The current object for the chest armor("leather_shoulders") gets deactivated and "vanishes" as intended, but the second object for the chest armor("metal_shoulders"), wich I manually deactivated in the inspector, doesn't activate, leaving a void where once was a chest.

    2 - Animation stops completely...

    I know a thing or 2 about programming and OO but I don't know C# syntax very well.

    Any help is appreciated :)
     
    Last edited: Feb 28, 2016
  3. ShokeR0

    ShokeR0

    Joined:
    Feb 24, 2016
    Posts:
    112
    What exactly are you trying to achieve here?
     
  4. Gordyne

    Gordyne

    Joined:
    Feb 22, 2016
    Posts:
    32
    Well, I imported a fbx wich has 10 animated objects wich are body parts (2x boots, 2x gloves, 2x chest, 2x helmets, 2xlegs) for my character. I'm trying to learn to activate/deactivate them so it seem the character is changing his gear.