I found a nice way to use tags and scenes.
ㅤ
public static class Tags
{
public readonly static string Player = "Player";
public readonly static string Fire = "Fire";
}
public static class Scenes
{
public readonly static string Main = "Main";
}
Create classes for tags and scenes as shown above.
ㅤ
ㅤ
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag(Tags.Fire))
{
Debug.Log("Player collided with Fire.");
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class RetryButton : MonoBehaviour
{
public void ReTry()
{
SceneManager.LoadScene(Scenes.Main);
}
}
Use tags and scenes as above.
ㅤ
ㅤ
ㅤ
ㅤ
ㅤ
How about using tags and scenes with the code above?
It is expected to solve problems caused by string typos.
Is there anything that could be a problem?