using System.Collections; using System.Collections.Generic; using UnityEngine; public class Checkpoint : MonoBehaviour { private CheckpointManager cm; private Cheese cheese; private CheeseCoin cheeseCoin; public Sprite green; void Start() { cm = GameObject.FindGameObjectWithTag("CheckpointManager").GetComponent(); cheese = GameObject.FindGameObjectWithTag("Player").GetComponent(); cheeseCoin = GameObject.FindGameObjectWithTag("Player").GetComponent(); } void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("Player")) { cm.lastCheckpointPos = transform.position; cm.lastCheeseCount = cheese.cheesecount; cm.isCheeseCoinCollected = cheeseCoin.cheeseCoinCollected; if (GetComponent().sprite != green) { FindObjectOfType().Play("checkpoint"); GetComponent().sprite = green; } } } }