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.
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();"
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 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.
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.
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
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); } } }
Thanks for making my suggestion so fast! Great vid👍
Thank you for the idea! :D
Thank you for the tutorial! You are the best!
You're welcome!
Thanks for the vid!
Thanks! :D
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.
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();"
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?
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?
@@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.
What do you want to see next?
Maybe an inventory system? or a simple hotbar with picking up items
@@imviciously this
@@imviciously that would be sweet. then adjusting player based on items picked up (gear and such)
Public Bool isMuddyWolfTHEMAN;
True.
as you can tell im a noob at this atm but your videos are really helping man thankyou so much!
will this work is i have a character selection Screen and a main menu screen where i hit play.
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.
Mine I'd not working. It's says it cannot load the destroy on load
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
Thank you
You're welcome
Dave chad
Dave is a real chad :)
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.
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);
}
}
}
Thank you
Can this work for unity 3d?
Yeah you just switch the player prefab!
it was all working fine until image.sprite became relevant in the script. Does 3d unity even have sprites?