I’m still a newbie at this, but I’ve spent a lot of time in the documentation today trying to figure this out. It’s time to admit I’m stuck.
I am attempting to make a character customization menu for my game. I think that part of the problem is that I’m using individual sprites for each moving part, rather than using sprites and redrawing each frame, so I have… a lot of parts. Since the mess of parts is working for me right now, I’m just going to leave well enough alone.
My problem is that the code I’ve got that’s supposed to change the skin tone when a button is clicked, isn’t working. I’m pretty sure I’ve got all the correct things hooked up in the correct places, and some (one) aspects are working (I can minimize then open the color selection menu, but it won’t start minimized).
I’ve at least gotten it so that I don’t have any errors.
I know leaving everything ‘public’ isn’t best practice. I’ll change all that when I’ve got it working.
I’m using this
tutorial from 2017, so for all I know, the only problem is something that’s been changed since then.
-
How do I fix this mess to make the colors change properly when the button is clicked?
-
Is there a way I can clean up the code, so the same 8 things don’t appear… everywhere?
a. I’m expecting it to get worse when I start adding hair and clothes.
- How do I fix the selection menu so that it only appears when it’s opened?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CharacterCreationManager: MonoBehaviour
{
public GameObject colorPanel;
public SpriteRenderer baseHead;
public SpriteRenderer baseBody;
public SpriteRenderer baseLArm;
public SpriteRenderer baseRArm;
public SpriteRenderer baseLHand;
public SpriteRenderer baseRHand;
public SpriteRenderer baseLLeg;
public SpriteRenderer baseRLeg;
public Color skin1;
public Color skin2;
public Color skin3;
public Color skin4;
public int whatSkinColor = 1;
void update()
{
SkinColor();
}
public void SkinColor()
{
if(whatSkinColor == 1)
{
baseHead.color = skin1;
baseBody.color = skin1;
baseLArm.color = skin1;
baseRArm.color = skin1;
baseLHand.color = skin1;
baseRHand.color = skin1;
baseLLeg.color = skin1;
baseRLeg.color = skin1;
}
else if(whatSkinColor == 2)
{
baseHead.color = skin2;
baseBody.color = skin2;
baseLArm.color = skin2;
baseRArm.color = skin2;
baseLHand.color = skin2;
baseRHand.color = skin2;
baseLLeg.color = skin2;
baseRLeg.color = skin2;
}
else if(whatSkinColor == 3)
{
baseHead.color = skin3;
baseBody.color = skin3;
baseLArm.color = skin3;
baseRArm.color = skin3;
baseLHand.color = skin3;
baseRHand.color = skin3;
baseLLeg.color = skin3;
baseRLeg.color = skin3;
}
else
{
baseHead.color = skin4;
baseBody.color = skin4;
baseLArm.color = skin4;
baseRArm.color = skin4;
baseLHand.color = skin4;
baseRHand.color = skin4;
baseLLeg.color = skin4;
baseRLeg.color = skin4;
}
}
public void ChangeSkinColor1() { whatSkinColor = 1; }
public void ChangeSkinColor2() { whatSkinColor = 2; }
public void ChangeSkinColor3() { whatSkinColor = 3; }
public void ChangeSkinColor4() { whatSkinColor = 4; }
public void OpenColorPanel()
{
colorPanel.SetActive(true);
}
public void CloseColorPanel()
{
colorPanel.SetActive(false);
}
}