Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Creating a simple checkpoint script.

Discussion in 'Scripting' started by azgoodaz, Jan 26, 2021.

  1. azgoodaz

    azgoodaz

    Joined:
    May 31, 2019
    Posts:
    3
    So I really don't know that much with coding to create an advance checkpoint system. I wanted to create a simple one where if I press a button, it goes to that specific checkpoint that I passed.

    "PreviousCheckpoint" would be the method/function that I have tied to my button. The data of the checkpoint is being captured, I can see the Vector3 data in the Inspector upon entering the trigger. Although upon pressing the button my character doesn't go to that checkpoint location.

    Does anyone one have a reason why?

    Script for my checkpoint:


    Script for my player giving to position of the player and the PreviousCheckpoint function.
    upload_2021-1-26_10-30-46.png

    Console shows data being captured at the checkpoints but not spawning character at said checkpoint.
     
  2. AbandonedCrypt

    AbandonedCrypt

    Joined:
    Apr 13, 2019
    Posts:
    69
    Looking at this I think the issue will be on your button script or my head-compiler is broken by tiredness. Are you sure PreviousCheckpoint() is called from your player script?
     
  3. azgoodaz

    azgoodaz

    Joined:
    May 31, 2019
    Posts:
    3
    My player script has nothing but movement data like (WASD, etc). Why would that script need to call the PreviousCheckpoint?
     
  4. azgoodaz

    azgoodaz

    Joined:
    May 31, 2019
    Posts:
    3
    Anyone have ideas on how to fix this?

    Updated the code a bit.

     
    Last edited: Jan 28, 2021
  5. AbandonedCrypt

    AbandonedCrypt

    Joined:
    Apr 13, 2019
    Posts:
    69
    I meant if the AZ_Playerpos Script is on your player and if PreviousCheckpoint even gets called, because you're setting the position with
    transform.position
    , meaning for it to work the component that houses the
    PreviousCheckpoint
    function needs to sit on the player. Giving us more code like that won't help, the thing doing the action should be the button, so we need to see that script.