Virtual Pet Game Template
  • VIRTUAL PET GAME TEMPLATE
  • Getting Started
    • 🎯 Project Setup Guide
    • 🧩 Home Scene Overview
    • 🗺️ UI Main Menu
    • 🗺️ LoadingManager
    • 🗺️ GameInstance
    • 🗺️ ToolsManager
    • 🗺️ AudioManager
    • 🗺️ LanguageManager
    • 🗺️ MonetizationManager
    • 🗺️ PlayerSave
  • Modifying the project
    • 🐾 How to Add a New Pet
    • 📜How Add a New Pet Rules
    • 💰 How to Add a New Currency
    • 🍎 How to Add a New Food Item
    • 🧢 Adding a New Accessory
    • 🎮 How to Add a New Minigame
  • Modifying Minigames
    • 🌤️ Minigame "Jump Sky"
    • 🍔 Minigame "Food Flicker"
    • 🐦 Minigame “Flappy”
    • 💎 Minigame “Gem Hunter”
Powered by GitBook
On this page
  • 🧱 Step 1 – Create a New PetData Asset
  • 🎨 Step 2 – Setup the Visual Prefab (PetModel)
  • 🧢 Equipping Accessories (Hats, Glasses, etc.)
  • 🍎 Step 3 – Configure Food Preferences (Optional)
  • Step 4 – Add to GameInstance
  • ✅ Final Checklist
  • 🧪 Runtime Notes
  • 🧩 Sample Code
  • 💡 Tips
  1. Modifying the project

🐾 How to Add a New Pet

This guide explains how to create, configure, and register a new pet in the Pet Care system using PetData, PetModel, and integration with food preferences.


🧱 Step 1 – Create a New PetData Asset

  1. In Unity, go to the Project tab.

  2. Right-click in your desired folder → Create > PetCareGame > Pet Data.

  3. This creates a new ScriptableObject with default values.

Fill Out the Fields

Field
Description

petId

Unique ID used to identify the pet (must be different from others).

petIcon

Sprite to show in selection menus or UI.

petName

Translated name per language.

petDescription

Translated short description.

petStats

Initial values for stats like health, energy, hygiene, etc.

petModel

Reference to the 2D or 3D model prefab containing the PetModel component.


🎨 Step 2 – Setup the Visual Prefab (PetModel)

Create or duplicate a pet prefab (2D or 3D) and configure it:

  1. Add the PetModel component to the root GameObject.

  2. Choose the model type: Model2D or Model3D.

  3. Configure the body renderers:

    • For 2D: Assign SpriteRenderer[] in bodyRenderer2D.

    • For 3D: Assign Renderer[] in bodyRenderer3D or use changeMaterial for shared material tinting.

  4. Add facial expressions for each mood:

    • Define unique id values (e.g., happy, sad, angry).

    • Link associated GameObjects (eyes, mouth, etc.) that visually reflect that mood.

  5. Configure:

    • Optional LeanTween animation settings.

    • Optional animation clips and audio feedback.

👉 Drag this prefab into the petModel field in the PetData asset.

🧢 Equipping Accessories (Hats, Glasses, etc.)

The PetModel prefab includes a section called Objects to Activate, which controls visual GameObjects linked to equipped cosmetic items such as hats, glasses, bows, etc.

Structure Overview

public CharacterObjects[] objectsToActivate;

Each entry in this list defines:

  • slotId: A slot type like "hat", "glasses", "bow"

  • items: A list of item IDs and associated GameObjects for that slot

How It Works

At runtime, the system checks which item is equipped using:

PlayerSave.GetSelectedClothes(slotId);

It will then:

  • Activate the objects for the matching itemId

  • Deactivate all others in the same slot

Example

If the player equips a hat with ID "hat_blue_cap":

  1. PlayerSave.SetSelectedClothes("hat", "hat_blue_cap") is called.

  2. At startup or refresh, PetModel.ApplyEquippedClothes() will:

    • Look for a CharacterObjects entry with slotId = "hat"

    • Find a CharacterObject where itemId = "hat_blue_cap"

    • Activate the assigned GameObjects only for this item

If no item is selected for a slot, all GameObjects in that slot are hidden.


🍎 Step 3 – Configure Food Preferences (Optional)

To personalize how much a pet likes specific foods:

  1. Open each FoodData asset in your project.

  2. Find the section Pet Preferences .

  3. Add a new entry for the pet you just created.

If no preference is registered for a pet, the system applies a default acceptance chance defined internally.


Step 4 – Add to GameInstance

In the home scene, select the GameInstance component and add the new PetData in the PetData field.


✅ Final Checklist


🧪 Runtime Notes

At runtime, the selected pet is determined by:

int selectedPetId = PlayerSave.GetPet();
PetData pet = GameInstance.Instance.GetPetDataById(selectedPetId);

The system uses this to:

  • Spawn the visual model

  • Access max stats for decay logic

  • Match food preferences

  • Handle equipped clothes and color tint


🧩 Sample Code

// To set a new pet ID (player selects)
PlayerSave.SetPet(2);

// To fetch pet name for UI
string name = petData.petName.GetByCurrentLanguage();

💡 Tips

  • You can reuse animations and materials across pets to reduce memory.

  • Consider adding unique sounds or accessories per pet.

  • Use meaningful petId values like 0 = Cat, 1 = Dog, etc.

Previous🗺️ PlayerSaveNext📜How Add a New Pet Rules

Last updated 28 days ago