Few examples based on my 🤖 ChatGPT with Unity video series on YouTube which is now supporting ChatGPT API and ChatGPT Python Wrapper BUT highly experimental.
🔔 Support all my work by Subscribing to YouTube thank you !
- A unity c# class script that creates 100 cubes by Using PrimitiveType cubes and then forms a three dimensional pyramid
- A unity c# class script that finds a PlayerArmature game object and get StarterAssetsInputs component and sets the "move" field to a vector2 with 0.3f for x and 0 for y, set "move" field to 0 after 3 seconds, then set "jump" field to true for 3 seconds
- A unity c# class script that loads a PlayerArmature from Resources consistently every 1/2 second, get StarterAssetsInputs component, set the "move" field to a vector2 with 1.0f for x and 0 for y, then set the "jump" field to true
-
Unity 2021.3.8f or greater
-
Roslyn C# - Runtime DLLs which you can get from the Resources folder. I'm also planning to add the Class Library project to GitHub which should allow you to generate these DLLs yourself.
-
Open any of the available scenes
-
Create an account in OpenAI
-
Get a new API Key and your API Organization
-
Update ChatGPTSettings file located under Assets/Settings/ChatGPT/
-
Each scene has a ChatGPTTester game object & script in the hierarchy, feel free to associate a new ChatGPTQuestion scriptable object as a reference as shown below:
ChatGPT is not officially available which means there're unofficial solutions which allow you to use code which gets ChatGPT answers from OpenAI by using browser automation tools. To do this do the following:
- Open a terminal and cd into this repo UnityChatGPT > Service folder
- Be sure you've Python 3.7 or greater installed if not (download it before proceeding)
- Create a Python virtual environment and activate it: (note that I am using Windows and some of these commands may differ a bit with macOS or Linux)
python -m venv chatgpt_env cd chatgpt_env .\Scripts\activate pip install pyreadline3 pip install git+https://github.com/mmabrouk/chatgpt-wrapper playwright install firefox pip install flask
- Login to OpenAI with the following command:
chatgpt install
- Now you should have an environment created and ChatGPT tested
-
Run our ChatGPT flask service which exposes an endpoint at /chatgpt/question/
python .\chatgpt_service.py
-
Test the ChatGPT flask service by doing a GET request at http://127.0.0.1:5000/chatgpt/status if you get the response below proceed to step 4:
{ "status": "ok" }
-
Open the Unity project and scene located at Assets > Scenes > ChatGPTLogger.unity
-
Go to Assets > Settings > ChatGPTSettings.asset and point the API Url to your ChatGPT flask service URL:
-
Ask ChatGPT a question as shown by clicking on "ChatGPTTester" game object:
-
Hit Play In Unity
- Write unity c# script monoBehavior named CubePlacer provides a method called Apply() which creates 5 primitive cubes 8 meter away from the camera along the z axis and each separated by 2 meters along the x axis and tilt it by 15 degrees on x