1
\$\begingroup\$

I am familiar with programming, but new to Unity. There seems to be a million ways to implement a right and left button for turning the plane. I'm wondering what the standard/easiest/best way to do this would be.

Do I make a single script that references the two sprites "left" and "right" and then detects mouse clicks and figures out whether they are over the sprite?

Should the buttons even be sprites / game objects? Or is there a better option for UI objects?

Should the left and right buttons both have their own scripts?

enter image description here

ps. I absolutely can't stand video tutorials, and it seems like that's all there is for unity :'( so if there is a good written tutorial on unity desgin patterns, let me know please :)

\$\endgroup\$
2
  • \$\begingroup\$ You're unlikely to find an objective answer or broad consensus on this. There are lots of ways to do this, and all of them work, without any major downsides or limitations. So, sticking with whatever makes the most intuitive sense to you is as good a plan as any. \$\endgroup\$ Commented Oct 1, 2017 at 22:39
  • \$\begingroup\$ You might want to look into the basics of the Unity UI system. \$\endgroup\$ Commented Oct 2, 2017 at 1:01

1 Answer 1

0
\$\begingroup\$

It doesn't matter. At all.

Unless you intend to make some user programmable interface, or to reuse your UI across a large number of games, the only thing that matters about making 2 buttons is that you won't spend more than a couple minutes doing it, thus pondering over how to implement them for a long period of time is a waste of time. You're currently doing a form of premature optimization.

The "official" way is to use the Unity.UI.Button, here's a random video tutorial.

Detecting clicks on sprites, which you suggest, is good too.

If you're really worried about a clean design, the one thing that matters with small things, like 2 buttons, is that the code is easy to delete and redo once you decide to do it a different way. If you just do it, it takes 10 minutes. If deleting the code takes no time and re-implementing it a different way takes another 10 minutes, you didn't really lose anything. But if you constantly worry about doing things the best possible way, instead of implementing solutions, you will lose a lot of time. Just do it, in a way that can easily be removed and replaced by "the best possible way" later, once you decided what "the best possible way" is.


It follows that when you need to design a piece of code which you won't be able to easily remove and replace later, it indeed is necessary to think long and hard about the design first.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.