Need assistance: Unity fun with my little girl

Hello!
My daughter and I are making the Monsterizer-3000! (Please see attached image)
It’s a simple 2D project we can do here while locked down in the house.
She will be drawing all the body parts.
What we want to happen is whenever you click the forward or backward arrow on a specific monster part, it will cycle through a list of them in a folder.
At the bottom, there is a field that will display the “Species name” of the monster.
So, after cycling through the 4 body parts and having the monster created in the view window, the name will also be generated in the “Species Name” field, based on what body parts were chosen.
I’m a total noob at scripts and such, my background is more in visual stuff, but pick things up quickly.
I assume, I need to make an array for each body part, and point that to their respective part folder, where the .png assets will be?
I’m just hoping to get assistance with this, so we can get to the fun stuff!
Much appreciation!

Hi.
Your idea is pretty much correct. As this project is only for your free time I wouldn’t worry about best solution performance wise, I would go for easiest one. So I would suggest the following:

For the whole idea, create GameObject with 2D sprite renderer attached to it. Also attach your own C# script “BodyPart” which would only hold public string name:

Drag that GameObject to your project hierarchy to create Prefab so you can re-use this when creating all body parts. Import all images you have to your project (drag & drop it in inspector) and then assign each image to new gameobject’s sprite renderer sprite (Double_LB in my example). So basically you want to create all your heads / body / hands / legs in your inspector and at the same time (you can see I already have two heads in my project hierarchy). Give each bodypart its name in your BodyPart script. Position all gameobject in their right place (obviously all your heads will overlap for now and so on). Once you have them all set up in inspector, leave only one body part active from each group - you need to untick that checkbox I’ve highlighted in my image.

So basically at this point you have all body parts ready, now you need some sort of script that would manage your game. Create BodyManager script which would have reference to all body groups, create two public functions per body group for “next” and “previous” body part in that group and all those functions will do, just simply enable / disable appropriate body parts. Also you want to have reference to your text input at the bottom and each time new body part is selected, you want update its text.

I’m adding quick code mock up I did. You would need to create buttons and assign on click events for each button to call those next/previous functions when clicked.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class BodyManager : MonoBehaviour
{
    public Text text;

    public BodyPart[] heads;
    public BodyPart[] hands;
    public BodyPart[] legs;
  

    private int active_head = 0, active_hand = 0, active_leg = 0;

    public void NextHead()
    {
        heads[active_head].gameObject.SetActive(false);
        active_head = active_head + 1;
        heads[active_head].gameObject.SetActive(true);
        UpdateText();
    }

    public void PreviousHead()
    {
        heads[active_head].gameObject.SetActive(false);
        active_head = active_head - 1;
        heads[active_head].gameObject.SetActive(true);
        UpdateText();
    }

    private void UpdateText()
    {
        text.text = heads[active_head].name;
    }

 
}

I’ve intentionally made it as simple as possible but for this project it’s alright I think. Here are few things for you to think of:

  • Handle case when there is no next / previous body part but next / previous button is clicked
  • Tweak UpdateText() function to concat body part names from all body groups

Good luck with your project. Hopefully you get the idea. :slight_smile:

Thank you very much for your response.
I have a few confusions…

When I started, I made the machine background image, I call a frame because it reminds me of a picture frame for the monster being created. It is screen-sized, and a background for everything else to lay over.

I imported arrow PNG images for all of the left and right arrow buttons, and made them UI Button objects.
Then I imported some PNG placeholder images (Temporarily just recolored versions of the same shapes for simplicity) for each body part, into each of their own folders, categorized by what body part. No sprites, just separate PNG images created and exported from Photoshop, because, for some reason, I was having a weird size issue attaching the images to sprites. I would keep trying to make the image larger, but only the bounding box around it got larger, not the actual PNG image.

Everything is under a CANVAS, set to Screen Space - Overly, and Scale with Screen Size.
When attempting to follow your method, I created a GameObject, Added component “Sprite Render” (it had the resizing issue. No resizing issue from importing images instead), then added the component, “script”, and named the script. In the inspector, there is no option within script to show the name. It only displays the “Script BodyPart”, not the “Name Bazinga”. This is most likely my fault. I seriously am not a scripter, but have learned a little here and there, like when I did tutorials to import my 3D assets into Unity and create terrain, sky, etc… I’m just trying to get enough info so my daughter doesn’t look at me like the idiot I am, and we can do this.

Regarding the species name portion… It isn’t actually an output of text. The name field at the bottom will actually be PNG images of my daughter’s writing.
The first part of the name will be based on the head, the second, based on the torso, the third part of the name will be from the legs and the last, the feet. So each name will be a 4-part name, but not a text output, just an image to represent the words.

Again, thank you for your response.

Hey Zynn3D,

It’s awesome that you’re spending time making this with your daughter! I’m also stuck in the house, and thought I’d take an hour and build this for you so you would have plenty of time to use it.

Attached is the unity package. All you have to do is drag it into a new unity project. A couple things to note:

There are 4 folders that are important for the “monster parts”.

Assets/Resources/MonsterParts/Heads
Assets/Resources/MonsterParts/Torsos
Assets/Resources/MonsterParts/Legs
Assets/Resources/MonsterParts/Feet

Make sure to drop the monster part image into its respective location. I just made 2 example parts for each category. The image sizes for the monster parts I used were 300x300 pixels, which seem to work pretty good. You won’t have to do anything else and it should will just work.

Also - the name that is generated at the bottom is just the name of the images.

You might get some weirdness if the sizes start getting strange, but they should fit together for the most part. Here’s the script for anyone curious, as well as a couple screen shots. Of course, if it doesn’t fit your specific needs, hopefully it will be easy for you to modify.

Have a wonderful day :slight_smile:

using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;

public class GameController : MonoBehaviour {

    private const int HEAD_INDEX = 0;
    private const int TORSO_INDEX = 1;
    private const int LEGS_INDEX = 2;
    private const int FEET_INDEX = 3;

    private List<Sprite[]> partSprites;
    private int[] partIndexes;
   
    public Image[] parts;
    public Text monsterName;

    private void Start() {

        partSprites = new List<Sprite[]> {
            Resources.LoadAll<Sprite>("MonsterParts/Heads"),
            Resources.LoadAll<Sprite>("MonsterParts/Torsos"),
            Resources.LoadAll<Sprite>("MonsterParts/Legs"),
            Resources.LoadAll<Sprite>("MonsterParts/Feet")
        };

        partIndexes = new[]{-1, -1, -1, -1};
    }

    public void PressedHeadLeft() {PressedArrow(HEAD_INDEX, -1);}
    public void PressedHeadRight() {PressedArrow(HEAD_INDEX, 1);}
    public void PressedTorsoLeft() {PressedArrow(TORSO_INDEX, -1);}
    public void PressedTorsoRight() {PressedArrow(TORSO_INDEX, 1);}
    public void PressedLegsLeft() {PressedArrow(LEGS_INDEX, -1);}
    public void PressedLegsRight() {PressedArrow(LEGS_INDEX, 1);}
    public void PressedFeetLeft() {PressedArrow(FEET_INDEX, -1);}
    public void PressedFeetRight() {PressedArrow(FEET_INDEX, 1);}

    private void PressedArrow(int index, int delta) {

        int tempIndex = partIndexes[index] + delta;

        partIndexes[index] =
            tempIndex < 0 ? partIndexes[index] = partSprites[index].Length - 1 :
            tempIndex > partSprites[index].Length - 1 ? partIndexes[index] = 0 :
            tempIndex;

        parts[index].sprite = partSprites[index][partIndexes[index]];
       
        if(parts[index].color != Color.white) parts[index].color = Color.white;

        string monsterNameText = parts.Aggregate("", (current, part) =>
            current + (part.sprite == null ? " ?" : " " + part.sprite.name));

        monsterName.text = monsterNameText;
    }
}

5679265–592321–monster-game.unitypackage (87.2 KB)

1 Like

For resize issue, it’s most likely you need to set sprite borders as I guess your image resolution doesn’t match sprite resolution / aspect ratio. Select image > Sprite Editor . It tells Unity how to scale your image. Anything inside border area is not scaled.
5679949--592444--sprite editor.png

You need to make that variable public if you want to see it in inspector but if said that name is actually images then you don’t really need this but I’m adding the code bellow for your future reference.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BodyPart : MonoBehaviour
{
    public string name;
    // Start is called before the first frame update
    void Start()
    {
      
    }

    // Update is called once per frame
    void Update()
    {
      
    }
}

ianswerquestions20 and lipisis

Thank you both so much for taking the time to help me.
It’s is very appreciated!
I’m sure I can get something working with what I’ve been given.
In fact, I am already thinking of other mechanics we can mess with, based off of this.
Again, thank you for your time.

~Zynn

2 Likes