Let's get your first Skillful Agent up and running in Unity. This guide assumes you have the SDK imported and your API key configured.
Adding Your First Agent
You have two ways to add a Skillful Agent to your scene:
Method 1: Adding Through Code
Create a new script (e.g., ExampleAgent.cs) and add this basic implementation:
using SkillfulAI.Agents;
using UnityEngine;
public class ExampleAgent : MonoBehaviour
{
private void Start()
{
// Add the Skillful Agent component to this GameObject
SkillfulAgent agent = gameObject.AddComponent<SkillfulAgent>();
// Select your agent by its dashboard name
agent.SelectAgentByName("YourAgentNameHere");
// Send your first message
agent.SendMessage("Hello, who are you?", response => {
// Log the AI's response
Debug.Log(response.text);
});
}
}
Method 2: Using the Unity Inspector
Create an empty GameObject in your scene
Add the SkillfulAgent component through the Inspector
Create a new script to interact with it:
using SkillfulAI.Agents;
using UnityEngine;
public class ExampleAgent : MonoBehaviour
{
private SkillfulAgent agent;
private void Start()
{
// Get the reference to the existing SkillfulAgent component
agent = GetComponent<SkillfulAgent>();
agent.SendMessage("Hello, who are you?", response => {
// Log the AI's response
Debug.Log(response.text);
});
}
}
Building Interactive Conversations
Let's create a more engaging conversation system:
public class InteractiveAgent : MonoBehaviour
{
private SkillfulAgent agent;
private bool conversationStarted = false;
void Start()
{
// Setup the agent
agent = gameObject.AddComponent<SkillfulAgent>();
agent.SelectAgentByName("YourAgentNameHere");
}
void Update()
{
// Start conversation when player presses Space
if (Input.GetKeyDown(KeyCode.Space) && !conversationStarted)
{
StartConversation();
}
}
void StartConversation()
{
conversationStarted = true;
agent.SendMessage("Hello! Can you tell me about yourself?", HandleResponse);
}
void HandleResponse(string response)
{
// Display the response (implement your UI logic here)
Debug.Log($"Agent says: {response}");
// You could trigger animations, update UI, or continue the conversation here
}
}
Handling Multiple Agents
Here's how to work with multiple agents in your scene:
public class MultiAgentManager : MonoBehaviour
{
private SkillfulAgent questAgent;
private SkillfulAgent tutorialAgent;
void Start()
{
// Setup quest agent
questAgent = gameObject.AddComponent<SkillfulAgent>();
questAgent.SelectAgentByName("QuestGiver");
// Setup tutorial agent
GameObject tutorialObj = new GameObject("TutorialAgent");
tutorialAgent = tutorialObj.AddComponent<SkillfulAgent>();
tutorialAgent.SelectAgentByName("TutorialGuide");
}
public void AskForQuest()
{
questAgent.SendMessage("What quests do you have available?", response => {
Debug.Log($"Quest Agent: {response}");
});
}
public void RequestTutorial()
{
tutorialAgent.SendMessage("Can you explain the basic controls?", response => {
Debug.Log($"Tutorial Agent: {response}");
});
}
}