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?
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.
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?
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.
Your answer
Follow this Question
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