Hello everyone i have an issue with a checkpoint object i want to make. Basically its one parent that has the animator and scrip attached and 3 more gameobjects as children that i want to enable in order.
First the idle checkpoint animation should play then on trigger enter open the text prefab and animation that the checkpoint is reached.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class CheckPoints : MonoBehaviour
{
public bool checkPointReached;
Animator anim;
public CheckPointManager CM;
private CameraFollow camFollow;
private CameraTransition camTr;
public float distance;
GameObject flag;
GameObject text;
GameObject checkpoint;
void Start()
{
anim = GetComponent<Animator>();
CM = GameObject.FindGameObjectWithTag("CM").GetComponent<CheckPointManager>(); // for player positioning
camFollow = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<CameraFollow>(); // for camera positioning
flag = transform.GetChild(0).gameObject;
text = transform.GetChild(2).gameObject;
checkpoint = transform.GetChild(1).gameObject;
text.SetActive(false);
flag.SetActive(false);
anim.Play("checkPointIdle");
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
checkPointReached = true; // reached checkpoint
CM.currentCheckPoint = gameObject; // set current object as latest checkpoint
Debug.Log("Activated checkpoint" + transform.position);
Debug.Log("Checkpoint " + CM.currentCheckPoint);
CM.boundsMax = camFollow.boundsMax;
CM.boundsMin = camFollow.boundsMin;
Debug.Log("Camera Bounds are :" + ("min") + camFollow.boundsMin + ("max") + camFollow.boundsMax);
text.SetActive(true);
flag.SetActive(true);
anim.Play("CheckPointEnabled");
}
}
public void LoopFlag()
{
anim.Play("FlagLoop");
}
}