UnityGameProjectsCode / Rise2Point0Game / Tools / SendInfoOnContact.cs
SendInfoOnContact.cs
Raw
using UnityEngine;
using System.Collections;

public class SendInfoOnContact : MonoBehaviour
{
    //call to a method in the achievement system when the player contacts this object
    private AchievementSystem achSys;
    private ScoreManager scoreMgr;

    [SerializeField] private bool stickyWall;
    [SerializeField] private bool slipperyWall;
    [SerializeField] private bool bouncyWall;
    [SerializeField] private bool deathWallProx;
    [SerializeField] private bool pathChange;
    [SerializeField] private bool secretWall;

    private void Start()
    {
        achSys = ObjectManager.GetObject(4).GetComponent<AchievementSystem>();
        scoreMgr = ObjectManager.GetObject(4).GetComponent<ScoreManager>();
    }

    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        {
            if (stickyWall)
                achSys.IncrementStickyWallUses();
            else if (slipperyWall)
                achSys.IncrementSlipperyWallUses();
            else if (bouncyWall)
                achSys.IncrementBouncyWallUses();
        }
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        {
            if (deathWallProx)
                achSys.SetNearDeathWall(true);
            else if (pathChange)
            {
                achSys.IncrementTimesSwitchedPaths();

                scoreMgr.ActivatePathSwitchBoost();

                GetComponent<ParticleSystem>().Play();

                bool gotGradient = false, gotBlocker = false;

                foreach (Transform childObject in transform.GetComponentsInChildren<Transform>())
                {
                    if (childObject.name == "Gradients")
                    {
                        FogWallFade tempWallFade = childObject.GetComponent<FogWallFade>();

                        tempWallFade.LerpStarted = true;
                        tempWallFade.DisableParticles();
                        gotGradient = true;
                    }

                    if(childObject.name == "Blocker Wall")
                    {
                        childObject.GetComponent<Animator>().Play("Blocker_Wall_Falling");
                        StartCoroutine(WaitToEnableBlockerWall(childObject.gameObject));

                        gotBlocker = true;
                    }

                    if(gotGradient && gotBlocker)
                        break;
                }

                GetComponent<BoxCollider2D>().enabled = false;
            }
            else if (secretWall)
                achSys.SetSecretUnlocked(true);
        }
    }

    private IEnumerator WaitToEnableBlockerWall(GameObject targetChild)
    {
        yield return new WaitForSecondsRealtime(1);

        targetChild.GetComponent<BoxCollider2D>().enabled = true;
    }
}