Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
  • Help Room /
avatar image
-1
Question by Codelyy · Jan 28, 2016 at 01:11 AM · c#return

What is the point of using return?

By return, i mean the for example: "Return true;" or "Return playerPosition;".

I know it's widely used but I just don't see a reason to use it. I recently found a script from another game that was simply made to detect the player's position in a function and then it returned the function.

For me, I wouldn't do something like that and I would simply create a variable and put something like

 Public Vector3 playerPosition = GameObject.Find("Player").transform.position;

Would someone be able to explain the point of using a Return and what type of situation i would possibly use it in?

Comment
Add comment · Show 3
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 Raresh · Jan 28, 2016 at 01:18 AM 1
Share

You aren't serious, are you? You might be new to program$$anonymous$$g and maybe don't have enough experience yet. Returns are very useful when making methods a.k.a functions. The GameObject.Find is slow and you shouldn't use it in Update. You can use a function from a game object as many times without much impact. Return is one of the core principles of program$$anonymous$$g. You NEED them for functions.

avatar image Codelyy Raresh · Jan 28, 2016 at 01:56 AM 0
Share

The one thing i mainly want to know though is, lets say for example I was wanting to find the player's position in the game, I notice a lot of unity games create a separate script for finding the player's position and returning the player's position so what is the reason for creating a separate script just to do that simple function then finding the player within your main script?

Unless there something else they add to the script apart from simply finding the player's position?

avatar image Owen-Reynolds · Jan 28, 2016 at 01:38 AM 1
Share

C# is a real program$$anonymous$$g language. Unity uses it because there are lots and lots of non-Unity places to learn how it works. So, it's a little like asking how to draw a cat. Everyone knows drawing is a different thing, not part of Unity. It isn't so obvious that Computer Program$$anonymous$$g is, too.

It takes a little practice to figure out what's special Unity extras, and what's standard C#. A good way is to just look it up and see if it's on lots of "How to learn C#" pages.

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

63 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

Related Questions

Premature level loading. String loads level, instead of Return key. 2 Answers

My Bool function is returning False but it should be true in my opinion. Csharp C# 0 Answers

Return key triggering a button OnClick? 1 Answer

Same code returning different results 1 Answer

Make a function call itself and return nothing until x = true 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges