We show you how to make a finish line for your game in Unity. This will work for both 2D and 3D games. Check out Hackingtons: www.hackington... Buy Some Merch: teespring.com/...
Assets\FinishLine.cs(9,23): error CS1061: 'Collision2D' does not contain a definition for 'tag' and no accessible extension method 'tag' accepting a first argument of type 'Collision2D' could be found (are you missing a using directive or an assembly reference?) ???
Better than this script using UnityEngine; using UnityEngine.SceneManagement; public class FinishFlag : MonoBehaviour { [Tooltip("Tag of the object that triggers the finish line.")] public string PlayerTag = "Player"; // You can set this to any tag in the Inspector [Tooltip("Name of the scene to load when the player reaches the finish line.")] public string SceneName; private bool levelCompleted = false; // To prevent multiple triggers private void OnTriggerEnter2D(Collider2D other) { // Check if the colliding object has the specified tag and level is not already completed if (other.CompareTag(PlayerTag) && !levelCompleted) { levelCompleted = true; CompleteLevel(); } } private void CompleteLevel() { // Load the next scene if (!string.IsNullOrEmpty(SceneName)) { SceneManager.LoadScene(SceneName); } else { Debug.LogError("Next scene name is not set!"); } } }
iv finnished the script and it says tyhere is no errors and iv also done everything else but when i colide with my finnishing line nothing happens any ideas?
great video!! I was wondering, what does the code need to say if I just want to start the same level over again? I am developing a one-level game for my uni project :)
when i use this its say the level doesnt exits what doesnt make any sense SceneManager.LoadScene(WinScreen); Assets\Scenes\Scripts\FinishLine.cs(13,31): error CS0103: The name 'WinScreen' does not exist in the current context
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class finish : MonoBehaviour { void OnTriggerEnter2D (Collider2D myCollider2D) { if (myCollider2D.tag == ("Player")) { SceneManager.LoadScene("Menu"); } } } Рабочий код перехода в другую сцену при касании финиша.
Hey man i use a custom Player movement script with it's own collision, and I changed OnTriggerEnter2D to OnCollisionEnter2D. The problem is that there is an error in the line collision.tag == "Player" the ".tag" highlights as wrong for me please help thanks :)
im using a player controller script that has makes its on collider when put on the player so if someone can tell me how to can do the same thing with the scripts collider