Momo-Space-Diner-Code-Repo
README.md

Scripts Overview

This repository contains several C# scripts for a Unity-based game that involves cooking, food preparation, and quest completion. The game features a variety of mechanics, including food cutting, cooking, quest management, and player interaction. Below is a summary of the key scripts, their functionalities, and explanations of the main features.

1. FoodQuest.cs

  • Purpose: Manages food quests, including dish requirements, ingredient tracking, and quest completion.
  • Key Features:
    • Quest Generation: Randomly generates dishes and required ingredients for each quest.
    • Quest Completion: Tracks whether the player has provided the correct ingredients for a dish.
    • Timer: Each quest has a timer, and if the player fails to complete it in time, the quest expires.
    • Network Synchronization: Ensures that quests are synchronized across all clients in a multiplayer environment.
  • Key Functions:
    • OnTriggerEnter(Collider other): Checks if the player has provided the correct ingredients for the quest.
    • AwardPoints(): Awards points to the player upon successful completion of a quest.
    • GetRandomDish(): Randomly selects a dish from a predefined list.
    • GetRandomIngredients(string dish): Generates a list of required ingredients based on the selected dish.
    • OnNetworkSetInitState(object[] args): Synchronizes the quest state across all clients.

2. FoodCut.cs

  • Purpose: Handles the cutting and cooking of food items.
  • Key Features:
    • Food Cutting: Allows players to cut food into smaller pieces using knives.
    • Cooking Mechanics: Tracks the cooking process, including overcooking and burning.
    • Network Synchronization: Ensures that food cutting and cooking are synchronized across all clients.
  • Key Functions:
    • OnCollisionEnter(Collision other): Detects collisions with knives and triggers the cutting process.
    • HandleCookingEvent_Oven(): Starts the cooking process when food is placed in an oven.
    • HandleCookingEvent_Grill(): Starts the cooking process when food is placed on a grill.
    • CookingProcess(GameObject cookedVersion, GameObject burntVersion, float cookingTime, float overcookTime): Manages the cooking timer and transitions between raw, cooked, and burnt states.

3. FruitSlicerGameManager.cs

  • Purpose: Manages a fruit-slicing mini-game, including spawning fruits, tracking player progress, and handling game states.
  • Key Features:
    • Fruit Spawning: Spawns fruits at random positions and trajectories.
    • Score Tracking: Tracks the player's score based on how many fruits they slice.
    • Combo System: Rewards players with higher scores for slicing multiple fruits in quick succession.
    • Lives System: Players lose lives if they fail to slice fruits, and the game ends if all lives are lost.
  • Key Functions:
    • SpawnFruit(): Spawns a fruit at a random position and applies a force to make it move.
    • OnFruitHit(): Increases the player's score and combo when a fruit is sliced.
    • OnFruitDropped(): Decreases the player's lives when a fruit is missed.
    • EndGame(): Ends the game and resets all variables.

4. OverCookedGameManager.cs

  • Purpose: Manages the overall game state, including spawning food quests, tracking player progress, and handling game difficulty.
  • Key Features:
    • Quest Spawning: Continuously spawns food quests for the player to complete.
    • Score Tracking: Tracks the player's score based on completed quests.
    • Difficulty Adjustment: Allows players to adjust the game difficulty, affecting the frequency and complexity of quests.
  • Key Functions:
    • SpawnFoodCard(): Spawns a new food quest card with a random dish and required ingredients.
    • CheckActiveFoodCards(): Checks for completed or expired quests and updates the score accordingly.
    • AddScore(int x): Adds points to the player's score when a quest is completed.

5. InstantiateObject.cs

  • Purpose: Handles the instantiation of food objects and manages their lifecycle.
  • Key Features:
    • Object Spawning: Spawns food objects when the player interacts with a spawner.
    • Object Tracking: Keeps track of spawned objects and ensures they are properly destroyed when no longer needed.
    • Network Synchronization: Ensures that object spawning is synchronized across all clients.
  • Key Functions:
    • SpawnObject(): Instantiates a new food object and adds it to the list of spawned objects.
    • HandleObjectDestroyed(GameObject destroyedObject): Removes a destroyed object from the list of spawned objects.

6. DishText.cs

  • Purpose: Manages the display of dish names and ingredients, ensuring they face the player.
  • Key Features:
    • Text Rotation: Ensures that the text always faces the player, making it easier to read.
    • Player Tracking: Tracks the player's position and adjusts the text rotation accordingly.
  • Key Functions:
    • Update(): Continuously updates the text rotation to face the player.

Key Features and Mechanics

  • Food Preparation: Players can cut, cook, and prepare various food items using knives, ovens, and grills.
  • Quest System: Players are given quests to prepare specific dishes, and they must gather the required ingredients to complete the quests.
  • Multiplayer Support: The game supports multiplayer, with all actions (e.g., cutting, cooking, quest completion) synchronized across all clients.
  • Score and Progress Tracking: Players earn points for completing quests and slicing fruits, and their progress is tracked throughout the game.
  • Difficulty Adjustment: Players can adjust the game difficulty, affecting the complexity and frequency of quests.

Usage

  1. Game Setup: Attach the OverCookedGameManager script to a GameObject in the scene to manage the overall game state.
  2. Quest Management: Use the FoodQuest script to create and manage food quests.
  3. Food Preparation: Attach the FoodCut script to food items to enable cutting and cooking mechanics.
  4. Fruit Slicing Mini-Game: Use the FruitSlicerGameManager script to manage the fruit-slicing mini-game.
  5. Object Spawning: Use the InstantiateObject script to spawn food objects in the game world.
  6. Text Display: Attach the DishText script to text objects to ensure they always face the player.

Audio Visualizer Scripts Section

This repository also contains several C# scripts for Unity that handle audio visualization. These scripts allow you to create dynamic visual effects (e.g., bars, lights, or materials) that respond to audio input. Below is a summary of the key scripts, their functionalities, and explanations of the main features.


Scripts Overview

1. AudioVisualizer.cs

  • Purpose: Visualizes audio spectrum data using bars that scale based on the audio input.
  • Key Features:
    • Single Audio Source: Focuses on the closest active audio source in the scene.
    • Smoothing: Smooths the spectrum data to create a more fluid visual effect.
    • Dynamic Scaling: Scales visualizer bars based on the intensity of the audio spectrum.
  • Key Functions:
    • Update(): Continuously updates the visualizer bars based on the audio spectrum data.
    • FindClosestAudioSource(): Finds the closest active audio source in the scene.

2. JukeBox.cs

  • Purpose: Manages a music player with visualizer bars that respond to the currently playing song.
  • Key Features:
    • Music Player: Allows users to play, pause, skip tracks, and adjust volume.
    • Visualizer Bars: Displays visualizer bars that react to the music.
    • Autoplay: Automatically plays the next song when the current one ends.
  • Key Functions:
    • PlaySong(int index): Plays the song at the specified index and updates the UI.
    • Update(): Updates the visualizer bars and progress bar based on the current song.
    • OnPausePlayButtonClick(MLPlayer player): Toggles between play and pause states.

3. MultiSourceAudioVisualizer.cs

  • Purpose: Visualizes audio spectrum data from multiple audio sources simultaneously.
  • Key Features:
    • Multiple Audio Sources: Accumulates spectrum data from all active audio sources in the scene.
    • Smoothing: Smooths the spectrum data for a more fluid visual effect.
    • Dynamic Scaling: Scales visualizer bars based on the combined audio spectrum.
  • Key Functions:
    • Update(): Continuously updates the visualizer bars based on the combined audio spectrum data.

4. MultiSourceAudioVisualizerLight.cs

  • Purpose: Visualizes audio spectrum data using a light that changes color and intensity.
  • Key Features:
    • Light Visualization: Changes the color and intensity of a light based on the audio spectrum.
    • Gradient Support: Uses a gradient to define color transitions based on the spectrum.
    • Multiple Audio Sources: Accumulates spectrum data from all active audio sources.
  • Key Functions:
    • Update(): Updates the light's color and intensity based on the combined audio spectrum data.

5. MultiSourceAudioVisualizerMaterials.cs

  • Purpose: Visualizes audio spectrum data by modifying material properties (e.g., color and emission) of visualizer bars.
  • Key Features:
    • Material-Based Visualization: Changes material properties (color and emission) based on the audio spectrum.
    • Gradient Support: Uses a gradient to define color transitions for the materials.
    • Multiple Audio Sources: Accumulates spectrum data from all active audio sources.
  • Key Functions:
    • Update(): Updates the material properties of the visualizer bars based on the combined audio spectrum data.

6. MultiSourceAudioVisualizerMaterialsColorGradient.cs

  • Purpose: Dynamically creates and manages visualizer bars that respond to audio spectrum data, with material properties controlled by a gradient.
  • Key Features:
    • Dynamic Visualizer Bars: Creates and positions visualizer bars dynamically based on the spectrum data.
    • Gradient Support: Uses a gradient to define color transitions for the materials.
    • Emission Control: Adjusts emission intensity based on the frequency range.
  • Key Functions:
    • UpdateVisualizerCount(): Ensures the number of visualizer bars matches the spectrum data count.
    • UpdateVisualizers(): Updates the scale and material properties of the visualizer bars based on the audio spectrum.

Key Features and Mechanics

  • Audio Spectrum Visualization: All scripts use Unity's GetSpectrumData to analyze audio and create visual effects.
  • Smoothing: Smoothing is applied to the spectrum data to create fluid and visually appealing animations.
  • Dynamic Scaling: Visualizer bars or lights scale based on the intensity of the audio spectrum.
  • Gradient Support: Several scripts use gradients to define color transitions, allowing for more visually interesting effects.
  • Multiple Audio Sources: Some scripts can handle multiple audio sources, combining their spectrum data for a more complex visualization.

Usage

  1. AudioVisualizer.cs: Attach this script to a GameObject with visualizer bars to visualize the closest audio source.
  2. JukeBox.cs: Attach this script to a music player GameObject to manage song playback and display visualizer bars.
  3. MultiSourceAudioVisualizer.cs: Use this script to visualize audio from multiple sources simultaneously.
  4. MultiSourceAudioVisualizerLight.cs: Attach this script to a light GameObject to create a light-based audio visualizer.
  5. MultiSourceAudioVisualizerMaterials.cs: Use this script to modify material properties (e.g., color and emission) based on audio input.
  6. MultiSourceAudioVisualizerMaterialsColorGradient.cs: Use this script to dynamically create and manage visualizer bars with gradient-based material effects.