• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by gabrimo · Jul 21, 2018 at 09:43 PM · width

Screen.width additional variable

This is probably some basic stuff, Im following a tutorial to start my RTS and I'm not so good on programming. That said, I comment almost every line of the tutorial's codes to ensure that I understand that line. Eventually, I reached in line that says:

Screen.width - ORDERS_BAR_WIDTH //Where "ORDERS_BAR_WIDTH" is a int constant

I don't understand what that variable is doing there. I visited Unity API but the documentation about "Screen.width" doesn't mention that I can put a variable after it.

Tutorial page where that piece of code is: http://www.stormtek.geek.nz/rts_tutorial/part3.php

It's on the "DrawOrdersBar()" creation.

Thanks.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Strixie13 · Jul 22, 2018 at 12:46 AM

Screen.width is simply the length of the users screen returned as a number. There are no rules to what you can put before or after it as long as everything is proper syntax.

Now, that tutorial looks super outdated and I would recommend using another. Unity overhauled their GUI system. You used to have to write out most of the measurements in code, so knowing the screen width would help with that. In this case, it looks like they are subtracting the length of a GUI element's width from the total of the screen, which would give you the numbers required to center it. For example, if the screen was 100 wide and the box was 50 long, you would have 25 on either side to center it.

Look at the new GUI system. It lets you scale up elements and anchor them to the screen without having to do any code. Should be under Unity's general tutorials, or there would be some on YouTube.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image gabrimo · Jul 22, 2018 at 02:54 AM 0
Share

I know that its outdated, but I only need a prototype for now and I didn't find any complete free tutorials with that style of game (with newer versions of Unity at least). Plus, the guy who made the tutorial seems have a good knowledge and organization. If you know a tutorial that is recent and good, feel free to tell me about it..

Thanks for the answer.

avatar image gabrimo gabrimo · Jul 22, 2018 at 03:04 AM 0
Share

Searched a little more and found this:

https://www.youtube.com/watch?v=0aFP4rmrNgc&t=1s

I'll take a look, it has positive feedback and is very recent. Probably will have more useful content.

avatar image Strixie13 gabrimo · Jul 22, 2018 at 12:12 PM 0
Share

These are the tutorials I was talking about for Unity. They go over all of the basics of the "new" UI system. https://unity3d.com/learn/tutorials/s/user-interface-ui

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

86 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

GUILayout.Box controlling Width 1 Answer

How can i change the width of the raycast? 1 Answer

LineRenderer End Width Bug 2 Answers

How to create a circle Handle/Gizmo with width parameter? 0 Answers

Toolbar That Wraps to Fit Any Horizontal Width (Code for You) 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges