Checkpoints and Respawning (2D Unity Tutorial)

Поділитися
Вставка
  • Опубліковано 30 вер 2024

КОМЕНТАРІ • 44

  • @Azirfx
    @Azirfx Рік тому +2

    Yeayyy, thanksss

  • @nyet0k753
    @nyet0k753 5 місяців тому +1

    my goat

  • @rngthunderlight4910
    @rngthunderlight4910 Рік тому +2

    thank you very muchchchchc

    • @NightRunStudio
      @NightRunStudio  Рік тому +1

      You’re welcome! Glad it was helpful.

    • @rngthunderlight4910
      @rngthunderlight4910 Рік тому +1

      I was really helpful only ur video worked other youtubers tutorials were not working thanks you very much

  • @Eaaaaaattmyasss
    @Eaaaaaattmyasss Рік тому +2

    this channel has been super helpful, thank you ! would you also be able to do a video on unlocking and swapping weapons for the player?

    • @NightRunStudio
      @NightRunStudio  Рік тому

      Thanks for the feedback! I actually have weapon-swapping planned as part of my melee combat series. I think it will probably be either part 5 or 6... so it is still a couple of weeks away. But it IS coming! :)

    • @Eaaaaaattmyasss
      @Eaaaaaattmyasss Рік тому

      @@NightRunStudio Oo okay well I’ll be waiting patiently :P

  • @陳強-l9z
    @陳強-l9z 4 місяці тому +1

    Yeah,it works well.

  • @brianross2517
    @brianross2517 Рік тому +2

    very succinct and to the point, you are a legend...awesome stuff...subscribed. 👍🙏

    • @NightRunStudio
      @NightRunStudio  Рік тому

      Ooohh… a legend. That’s a new one 🤨. Thanks for the sub, and good luck with your project!

  • @gurbetcitv2482
    @gurbetcitv2482 Рік тому +1

    Hi there, I'd like to ask how to reset health after checkpoint, should I write to respawn script or some separate one? I'd be appreciated if u or someone could help 🙏

    • @NightRunStudio
      @NightRunStudio  Рік тому +1

      The easiest way to do this is probably right in your respawn script. Let's imagine that your health is handled by a script on the player called PlayerHealth, and your player's gameObject is named is Bob...
      1) First, you need to make a reference to that script. This is usually done at the top of your code with all the other variables.
      public PlayerHealth playerHealth;
      2) Now, you need to tell your script where to find PlayerHealth. This is usually done in your start method.
      playerHealth = GameObject.Find("Bob").GetComponent();
      3) Now you send the message to your playerHealth script. Right before transform.position code that respawns my player, I would write something like:
      playerHealth.health = playerHealth.maxHealth;
      I hope that helps!

  • @needyboxman
    @needyboxman Рік тому +1

    nice video

  • @siardankalingga
    @siardankalingga 9 місяців тому +1

    thank you very much....

    • @NightRunStudio
      @NightRunStudio  9 місяців тому

      My pleasure! Thanks for taking the time to leave a comment!

    • @KHAIRULAMINBINKHAIRULHELMIPela
      @KHAIRULAMINBINKHAIRULHELMIPela 9 місяців тому

      @@NightRunStudio using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      public class PlayerHealth : MonoBehaviour
      {
      public int health;
      public int maxHealth = 10;
      public SpriteRenderer playerSr;
      public PlayerMovement playerMovement;
      // Start is called before the first frame update
      void Start()
      {
      health = maxHealth;
      }
      // Update is called once per frame
      public void TakeDamage(int amount)
      {
      health -= amount;
      if(health

    • @NightRunStudio
      @NightRunStudio  9 місяців тому

      @@KHAIRULAMINBINKHAIRULHELMIPela the health system that I use as a demonstration in this video is very similar to the one from my health system video. The respawn code in this video should fit in perfectly... you just have to write the respawn code, and then change the death conditions (instead of turning off the sprite renderer like you are now, you can call the respawn script (that part is as 9:04). Hope that helps!

    • @KHAIRULAMINBINKHAIRULHELMIPela
      @KHAIRULAMINBINKHAIRULHELMIPela 9 місяців тому

      ​​@@NightRunStudioIs it seperate script or should I mix the code with the script above?Also if you can,please wrote the code because I am a beginner

    • @NightRunStudio
      @NightRunStudio  9 місяців тому

      @@KHAIRULAMINBINKHAIRULHELMIPela Have you followed the whole video? it pretty much walks you through all the steps. The only difference is that in the "HealthTest" example I provide, you will use your health script instead.
      Sorry, I answer a lot of questions; writing scripts would just take too much time if I did it for everyone :(

  • @niveditaph8778
    @niveditaph8778 Рік тому

    Bro this script is not working when I go to checkPoint it does not work what should I do?

    • @NightRunStudio
      @NightRunStudio  Рік тому

      I’m afraid I’ll need more details to figure this out. What is not working? Have you tried placing any debug.logs into your script so you can find out which parts are running and which parts are not?

    • @niveditaph8778
      @niveditaph8778 Рік тому

      @@NightRunStudio It's not working So I'm giving you my script both player respawn n checkPoint to using UnityEngine;
      using UnityEngine.SceneManagement;
      public class CheckPoint : MonoBehaviour
      {
      public GameObject greenFlag;
      public GameObject redFlag;
      private PlayerRespawn playerRespawn;
      // Start is called before the first frame update
      void Start()
      {
      playerRespawn = GameObject.Find("Player").GetComponent();
      }

      private void OnTriggerEnter2D(Collider2D collision)
      {
      if (collision.gameObject.name == "Player")
      {
      playerRespawn.RespawnPoint = transform.position;
      redFlag.SetActive(false);
      greenFlag.SetActive(true);
      Debug.Log("check");
      }
      }
      ================================================================================================================================================================================================

      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      public class PlayerRespawn : MonoBehaviour
      {
      public Vector3 RespawnPoint;
      public void RespawnNow()
      {
      transform.position = RespawnPoint;
      }
      private void OnCollisionEnter2D(Collision2D collision)
      {
      if (collision.gameObject.tag == "Death")
      {
      RespawnNow();
      Debug.Log("Swim into the Lava");
      }
      }
      }
      this is the script pls Check it

    • @niveditaph8778
      @niveditaph8778 Рік тому

      @@NightRunStudio yo ! Pls answer my reply pls

    • @NightRunStudio
      @NightRunStudio  Рік тому

      Do your debugs print in the game? If not, then I suspect something is wrong in Unity itself. Double check that your player is actually named player (with a capital P), and that your death object is actually tagged. Make sure that all of the public variables you created are actually filling in. When you say it’s not working, it’s hard to know what is wrong. It’s a lot more helpful if I know which variables are not getting filled in in the inspector, and which debugs are not printing.

    • @niveditaph8778
      @niveditaph8778 Рік тому

      @@NightRunStudio OK I've check