void Start() { lineRenderer = GetComponent <LineRenderer>(); lineRenderer.useWorldSpace = true; joint = GetComponent <DistanceJoint2D>(); rigidbody = GetComponent <Rigidbody2D>(); renderer = GetComponent <SpriteRenderer>(); audio = GetComponent <AudioSource>(); collider = GetComponentInChildren <Collider2D>(); if (volume <= 0) { volume = CalculateVolume(); } else { UpdateVolume(); } // Auto-populate camera if it is missing. targetCamera = targetCamera ?? Camera.main; originalColor = renderer.color; // Search for a cargo object if there are no others. cargo = cargo ?? FindObjectOfType <CargoBehaviour>(); }
void OnTriggerEnter2D(Collider2D other) { if (isActivated) { return; // Don't activate multiple times. } CargoBehaviour cargo = other.GetComponent <CargoBehaviour>(); if (cargo) { particles.Play(); animator.SetBool("Open", isActivated = true); audio.PlayOneShot(activationSound, audioVolume); // Run this first to set the game state to victory. GameManager.instance.NotifyVictory(); cargo.Pop(); } }
public void NotifyDefeat(float delay = 4f) { if (levelState != LevelState.inGame) { return; } // Turns off the HUD and opens the game over screen. HUDElements.objectivePointer.gameObject.SetActive(false); HUDElements.HUD.SetActive(false); GameMenuManager.instance.Open("Game Over", delay); levelState = LevelState.defeat; // Pop the player's balloon. CargoBehaviour cargo = player.GetComponent <CargoBehaviour>(); if (cargo) { cargo.Pop(); } }