Using Unity with ChatGPT on macOS for vibe coding is dangerously easy

本文共有11199个字。 # / a

AI has made it somewhat easier for non-developers to create apps but using ChatGPT with Unity in macOS, but it won't turn you into John Carmack overnight.

The growth of AI chatbots such as ChatGPT has made considerable changes to knowledge-centric industries. Instead of needing to know how to do difficult tasks that require years of effort, you now have a way to get the job somewhat done by asking an app to do it for you.

As a person who writes for a living, I'm intimately aware of how good AI can be when crafting text on a subject, and I'm not a fan. It's not perfection, and makes Google summaries frustratingly mostly-wrong compounded by searchers just bouncing off summaries that remain mostly uncredited.

That said, things like Apple's Writing Tools are pretty good at performing simple writing tasks for non-writers.

I also know how AI can be disruptive to visual arts too. My artist partner and AppleInsider's own artist-in-residence Brian Patterson have previously discussed the various dilemmas surrounding AI art, copyright, and attribution.

Obviously, AI services can do a lot, and get you most of the way to completing a large task. But at the same time, you may get more benefit from using it as a learning tool, so you can perform those same tasks for yourself.

Thanks to some external prodding by my boss Mike Wuerthele, I ended up going through my own experience working with ChatGPT to work on something I've wanted to do for decades.

Making a game.

Game-changing education

The reason I started using ChatGPT for game production was because of my partner. She is doing a master's in game development, and her group was tasked with making a game.

As the more technically minded person of this small household, and based on previous occasions, I anticipated that she would be asking me questions about development at some point. Inevitably, I wouldn't know the answer or have an idea of where to go with the query, and feel useless.

Since she would be using Unity as part of a group to make small games as part of the course, I figured that I should learn how to use it so I can at least try to help her out.

I'll admit that my background isn't in development at all, but I'm not completely starting from zero. I have a HND from the University of Glamorgan in "Computing" I was handed in 2004, which means I have some experience working in things like PHP, a bit of C++, and some very basic programming concepts.

Screenshot of a step-by-step guide for implementing word validation in Unity using C# code, including code snippets and explanations.

The usual route would be to look at the many YouTube and online guides to learn how to use Unity itself, as well as to write in C#. There is a lot of manual pages for all of the various functions available within Unity, and it would take a long time to learn that way.

I figured that one of the best ways forward was to make my own small game. A low-in-scope app that lets me learn the absolute basics as I go along, gradually turning it into a full product.

That project would be a word game. A 2D affair, instead of jumping straight to the tougher 3D-based games that are a lot more attractive to a first-timer.

While using Google-fu would be the old way of doing things, I also figured that I could try to take advantage of an actual tutor. Or, in this case, ask ChatGPT for help.

Good vibe coding

ChatGPT has the capability to write code, and it also has the ability to understand game engines. As it will have scanned practically every page of the Unity manuals and guides on the Internet, it is going to be a very well-versed developer's assistant.

The idea was that I would ask ChatGPT to help me learn by asking it how to do a small task, and requesting it to explain the thought process behind it all. It would explain concepts and why things were being done in a specific way, and the project would be constructed gradually.

I outlined the basic idea of the word game to ChatGPT so it knew what the basic idea was, and I asked it to come up with a basic plan of action to get the basics of the game in place.

In return, it came up with a multi-phase plan, complete with generalized instructions for each section. Surprisingly, it also included code snippets I could either write for myself or to copy and paste directly into the script files.

Indeed, if I didn't want to actually touch the code, I could instead allow ChatGPT to directly edit the files for me. In March, an update to ChatGPT allowed it to read files open in Xcode, and to make changes directly to the code for you.

Dropdown menu overlaying text, showing application options like Xcode, BBEdit, Notes, Notion, and Script Editor. 'Add' button is next to Xcode with others marked 'Not running.'

This can certainly save a lot of effort for an intrepid or lazy coder. You could explain in simple terms what you want ChatGPT to do, and it will do it for you in Xcode.

This is what is referred to as Vibe Coding, a recently emerging technique where developers focus on the "vibe" of the app itself and leave AI to handle the actual implementation.

Vibe coding does offer users the capability to make apps by themselves when they have little experience. It's not hard to see it being used to create simple apps, both for experienced coders and newbies to the field.

However, there is a danger with the technique. By leaning on AI to do all of the code, a developer can certainly get the work done, but a new developer may not necessarily learn much about coding from the experience.

I tried to steer clear of utilizing vibe coding completely, as this was meant to be a learning exercise for me. I did ask it to implement code a few times to try it out, and I can see the allure, but it's not great from a learning standpoint.

Fixing the broken - or, why "Error near or before end" isn't a thing anymore

While I wasn't prepared to allow ChatGPT to completely write an app for me, I was allowing it to guide me through gradually producing a game from scratch. It helped with letter spawning, timers, win/loss conditions, and even checking words against a word list.

Working gradually also allowed me to test the game at each stage. I was glad that I went down this route, as it enabled ChatGPT to shine in another way.

When a problem arose, I was able to tell ChatGPT that there was an issue and describe it to the app. Occasionally, this was caused by blips in ChatGPT's code, and sometimes it was human error.

Remembering the previous steps taken in development, ChatGPT would diagnose probable causes for the fault and things to check. Even better, if there was an error within Unity, I could copy and paste the log into ChatGPT, and it would have more data points to determine what happened.

ChatGPT interface showing a conversation about Unity troubleshooting. Steps include checking for duplicate classes, namespace issues, script file location, clearing Unity cache, and script class declaration.

In cases where it's an issue in code, ChatGPT would offer a copyable refresh of a script, which could then be pasted into place and fix the problem.

That connection with Xcode also came in handy, as I could ask it to check any code I had written myself. It would check for errors, and even provide ways to improve what's there, complete with explanations.

It was probably a good thing that I checked throughout the project. The last thing you want is to do all of the work in the hope it all works, but then find a really difficult-to-find error right at the end.

Smaller haystacks are better when searching for needles. Even with the help of ChatGPT.

Even if we ignore the relative ease of using ChatGPT for vibe coding, asking it to check code for issues and improvements could be a game-changer.

I would hate to imagine checking through thousands of lines of code to find the one mistake that's causing everything to fail. I may not have an intern I could pass the task onto, but ChatGPT acts as a digital one for me.

A good start

After probably about six hours of effort across a few evenings, I managed to get to what could be technically described as a game. It had a game-over condition, it checked that entered words were on an acceptable words list, and letters were added to the rack in a random way.

What ChatGPT helped me make is far from what you would actually consider a full game experience. It's a basic screen, not flashy, missing sound and music, and many other things that you would expect from any sort of game.

It is a functional game. Technically. If you squint at it and tilt your head just-so.

What it is, is really the core of a game, not a fully fleshed-out version.

Game screen with timer, randomized letters, input box with 'ju', and buttons for submit and new round. Green text reads 'Accepted: YOU'. 'Game Over!' displayed below input.

At this stage in the project, I can say I have made a game, but I can't say I've released a game. To get to the stage where I could confidently release it to the world without being embarrassed by it requires a lot more work.

It's been a fun project. I can see the potential in staying the course and properly finishing it off. Doing so should help round out my education in Unity and C#, and therefore better able to help with my partner's inevitable queries.

I'm going to continue adding to it, by refining the gameplay and adding the typical bells and whistles. A basic menu wouldn't go amiss either. We'll be talking about the process more, probably after the iPhone 17 releases.

But doing so will probably mean spending quite a few weeks, or even months, building it up into a proper gaming experience. Maybe even one that could be turned into an iPhone-compatible game if it reaches a suitable finished state.

It won't make me a sudden App Store millionaire, or even hundred-aire anytime soon. This is the case with most coders, though.

It is making the 15-year-old me who wanted to make games very happy.

版权声明:本文来源自网络,经修正后供个人鉴赏、娱乐,如若侵犯了您的版权,请及时联系我们进行删除!

添加新评论

暂无评论