Character Selector in Unity

Поделиться
HTML-код
  • Опубликовано: 1 янв 2025

Комментарии • 30

  • @senate_66
    @senate_66 3 года назад +3

    Thanks for making my suggestion so fast! Great vid👍

    • @MuddyWolf
      @MuddyWolf  3 года назад

      Thank you for the idea! :D

  • @BowonKim-lq5os
    @BowonKim-lq5os 2 года назад +3

    Thank you for the tutorial! You are the best!

  • @imviciously
    @imviciously 3 года назад +1

    Thanks for the vid!

  • @crissmaldonadoh
    @crissmaldonadoh 2 года назад +1

    Hi, when I try to run the game I get the follow error: the object of type 'gameobject' has been destroyed but you are still trying to acces it., does anyone know how to fix it? Thanks in advance.

  • @Devsycode
    @Devsycode Год назад +3

    if any of yall have issues with text mesh pro, like if you are using it for the name, make sure at the top to say using TMPro; and then at line 30 make sure to say "TextMeshProUGUI text = option.GetComponentInChildren();"

  • @HatredPL-z2u
    @HatredPL-z2u Год назад +1

    The tutorial is very nice, but it does not cover two things that affect the further gameplay:
    1. If the camera is tracking the player in the next scene (level), applying prefab will automatically disable the camera tracking.
    -> (this can be solved with an additional script (I use cinemachine) that is added to the camera)
    2. It is possible to press the 'start game' button without first selecting a player, in effect we start a level that we cannot play.
    Any chance you'll complete this tutorial with another part?

    • @Leo-cv5mh
      @Leo-cv5mh Год назад

      Can't you just have a camera for each character in the prefab?
      And can you not just make the start game button appear after a character is selected?

    • @HatredPL-z2u
      @HatredPL-z2u Месяц назад

      @@Leo-cv5mh Yes you can, but it means that each player will have a camera assigned to them as a child object (I think that's what you're asking about). As a result, if you modify the camera on player 1 because you wanted to improve something, you'll have to change it on each player or make a prefab from the camera, and each player will have that prefab as a child.
      My proposal is different and adapts to the player itself. 1 camera + cinemachine + group tracking (where you put as many player prefabs as you want in the list). The camera will always center on the player (unless you put two or more in the scene, then it will try to actively stay in the middle of the players).
      As for the 'start game' button that appears after selecting a player, of course you can, that's what I did, additionally I added a button in the background that deactivates the player selection.

  • @MuddyWolf
    @MuddyWolf  3 года назад +2

    What do you want to see next?

    • @imviciously
      @imviciously 3 года назад +3

      Maybe an inventory system? or a simple hotbar with picking up items

    • @nonsuspicious
      @nonsuspicious 3 года назад +2

      @@imviciously this

    • @Bscoop75
      @Bscoop75 3 года назад +2

      @@imviciously that would be sweet. then adjusting player based on items picked up (gear and such)

  • @mopreachmopower621
    @mopreachmopower621 2 года назад

    Public Bool isMuddyWolfTHEMAN;
    True.
    as you can tell im a noob at this atm but your videos are really helping man thankyou so much!

  • @TheFlipSide.
    @TheFlipSide. 2 года назад

    will this work is i have a character selection Screen and a main menu screen where i hit play.

  • @aycaogur659
    @aycaogur659 9 месяцев назад

    I had an issue on the CharacterSelector script. "button.onClick" does not work on me, I got an error 'CS1061' eventhough I used 'using UnityEngine.UI;' Does anyone know how to solve it? I am using 2022 unity.

  • @snackiejr7785
    @snackiejr7785 2 года назад

    Mine I'd not working. It's says it cannot load the destroy on load

  • @lilili765
    @lilili765 Год назад

    Does this still work if you make it so when you pres that button it goes to a level select screen and then the level you are actually playing. Basically a mario kart system

  • @ChrizBob
    @ChrizBob 3 года назад +1

    Thank you

  • @hermit5788
    @hermit5788 3 года назад +1

    Dave chad

    • @MuddyWolf
      @MuddyWolf  3 года назад

      Dave is a real chad :)

  •  Год назад +1

    If i to the same i get:
    NullReferenceException: Object reference not set to an instance of an object
    CharacterSelectionUI.Start () (at Assets/CharacterSelectionUI.cs:30)
    Spawns only one Option clone.
    If i deleted nex code in CharacterSelectionUi:
    Text text = option.GetComponentInChildren();
    text.text = c.name;
    Image image = option.GetComponentInChildren();
    image.sprite = c.icon;
    Spawns all three characters, but without names (logical).
    Do someone know whats wrong? Oh and on GitHub you named CharacterSelectionUI without second "c", if it important.
    Also thanks for all work, this is awesome stuff and now i understand how to things like that.

    •  Год назад +2

      Updated:
      Use TextMashPro, this is right version, you can delete Debug if you want
      using TMPro;
      using UnityEngine;
      using UnityEngine.UI;
      public class CharacterSelectionUI : MonoBehaviour
      {
      public GameObject optionPrefab;
      public Transform prevCharacter;
      public Transform selectedCharacter;
      public Character nameSetting;
      private void Awake()
      {
      foreach (Character c in GameManager.instance.characters)
      {

      GameObject option = Instantiate(optionPrefab, transform);
      Button button = option.GetComponent();
      button.onClick.AddListener(() =>
      {
      GameManager.instance.SetCharacter(c);
      if (selectedCharacter != null)
      {
      prevCharacter = selectedCharacter;
      }
      selectedCharacter = option.transform;
      });
      TextMeshProUGUI text = option.GetComponentInChildren();
      if (text == null)
      {
      Debug.LogError("Text component not found in option prefab!");
      }
      else
      {
      text.text = c.name;
      }
      Image image = option.GetComponentInChildren();
      if (image == null)
      {
      Debug.LogError("Image component not found in option prefab!");
      }
      else
      {
      image.sprite = c.icon;
      }
      }
      }
      private void Update()
      {
      if (selectedCharacter != null)
      {
      selectedCharacter.localScale = Vector3.Lerp(selectedCharacter.localScale, new Vector3(1.2f, 1.2f, 1.2f), Time.deltaTime * 10);
      }
      if (prevCharacter != null)
      {
      prevCharacter.localScale = Vector3.Lerp(prevCharacter.localScale, new Vector3(1f, 1f, 1f), Time.deltaTime * 10);
      }
      }
      }

    • @benjavel
      @benjavel 11 месяцев назад

      Thank you

  • @BoxxylovesU
    @BoxxylovesU 2 года назад +1

    Can this work for unity 3d?

    • @MuddyWolf
      @MuddyWolf  2 года назад

      Yeah you just switch the player prefab!

  • @echiko4932
    @echiko4932 7 месяцев назад

    it was all working fine until image.sprite became relevant in the script. Does 3d unity even have sprites?