Save points from one scene to another?

I am making a 2D platformer and I want to know how I can make it so when the player collects coins, it travels to the other scene and beyond.

Here are the scripts that use the points

FIRST SCRIPT

using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;

public class GameMaster : MonoBehaviour
{
    public int points;
    public Text pointsText;

    private void Update()
    {
        pointsText.text = points.ToString();
    }
}

SECOND SCRIPT

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    public float speed;
    public float jumpForce;
    private float moveInput;

    private Rigidbody2D rb;

    private bool facingRight = true;
    private bool isGrounded;

    public Transform groundCheck;
    public float checkRadius;
    public LayerMask whatIsGrounded;

    private int extraJump;
    public int extraJumpValue;

    private GameMaster gm;

    private void Start()
    {
        extraJump = extraJumpValue;
        rb = GetComponent<Rigidbody2D>();
        gm = GameObject.FindGameObjectWithTag("GameMaster").GetComponent<GameMaster>();
        
    }

    private void FixedUpdate()
    {
        isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGrounded);

        moveInput = Input.GetAxisRaw("Horizontal");
        rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);

        if (facingRight == false && moveInput > 0)
            Flip();
        else if (facingRight == true && moveInput < 0)
            Flip();
    }

    private void Update()
    {
        if (isGrounded == true)
            extraJump = extraJumpValue;

        if (Input.GetKeyDown(KeyCode.Space) && extraJump > 0)
        {
            rb.velocity = Vector2.up * jumpForce;
            extraJump--;
        }
        else if (Input.GetKeyDown(KeyCode.Space) && extraJump == 0 && isGrounded == true)
            rb.velocity = Vector2.up * jumpForce;
    }

    void Flip()
    {
        facingRight = !facingRight;
        Vector3 Scaler = transform.localScale;
        Scaler.x *= 1;
        transform.localScale = Scaler;
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.CompareTag("Coin"))
        {
            Destroy(collision.gameObject);
            gm.points += 1;
        }
    }
}

I think the simplest way to do it is by saving your points using PlayerPrefs.

This is how you save it:

     private void OnTriggerEnter2D(Collider2D collision)
     {
         if (collision.CompareTag("Coin"))
         {
             Destroy(collision.gameObject);
             gm.points += 1;
             PlayerPrefs.SetInt("Points", gm.points);
         }
     }

And this is how you get the saved value:

 public class GameMaster : MonoBehaviour
 {
     public int points;
     public Text pointsText;

     private void Start()
     {
         points = PlayerPrefs.GetInt("Points", 0);
     }
 
     private void Update()
     {
         pointsText.text = points.ToString();
     }
 }

If you just want to save it between scenes you could also just move your GameMaster to DontDestroyOnLoad.

Hello.

This is Unity Answers, Not Unity Code Providers…

Go read the manual and watch tuttorials about Unity Data Persistence.

good luck! Bye!