Forum begins after the advertisement:


[Part 7] Save system issues

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part 7] Save system issues

Viewing 16 post (of 16 total)
  • Author
    Posts
  • #13498
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    Your code looks great. If you want to prevent the occasional input drop, you can move Input.GetButtonDown() over to Update() and you are good to go:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;
    
    public class Savepoint : MonoBehaviour
    {
        public bool interacted;
        private Animator anim;
        private bool interactionCheck;
    
        // Start is called before the first frame update
        void Start()
        {
            anim = GetComponent<Animator>();
            anim.Play("Flag_Down");
        }
    
        // Update is called once per frame
        void Update()
        {
            if(interactionCheck && Input.GetButtonDown("Interact"))
            {
                interacted = true;
                //anim.Play("Flag");
                anim.SetTrigger("Active");
    
                SaveData.Instance.savepointSceneName = SceneManager.GetActiveScene().name;
                SaveData.Instance.savepointPos = new Vector2(gameObject.transform.position.x, gameObject.transform.position.y);
                SaveData.Instance.StoreSavepoint();
                SaveData.Instance.SavePlayerData();
                Debug.Log("saved");
            }
            else
            {
                interacted = false;
            }
        }
    
        private void OnTriggerStay2D(Collider2D collision)
        {
            if(collision.CompareTag("Player") && Input.GetButtonDown("Interact"))
            {
                interactionCheck = true;
            }
            else
            {
                interactionCheck = false;
            }
        }
Viewing 16 post (of 16 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: