Please read the previous article before reading this article: http://www.cnblogs.com/shenggege/p/4179012.html
Originally an article can be said, but the last time just realized some of the known features
Later in the actual use of a problem encountered, please look at the figure
3D scene! Near big far small!
When I move the angle of view very far, the information of the head becomes very small, so I can't see what it shows.
And if there are multiple players, each player has overhead information.
When I was far away from the other player, the player's top-of-the-head information was invisible.
So what's the point of getting overhead information?
This article solves this problem, in fact very simple
The following are resolved:
Do smart little friends see what they're thinking at a glance?
Whether you understand it or not, please read this article patiently! Wait for me one by one.
First, we zoom in all the fonts we want to display 10 times times.
I am afraid that you understand the mistake I illustrate:
Exphudtext--fontsize: I used to be 20, and now I change to 200.
Namelabel--fontsize: Ibid.
Here may be a small partner to ask: What if there are pictures?
Well, indeed, some projects need to make blood bar, light font amplification of blood bar or can't see clearly not equal to White said?
I don't need a blood bar in my project, we'll skip it here ....
Haha, a joke with everyone!
That's the question we're going to say at the end.
I use a VIP logo in the project, when the player spends money to charge VIP, this logo will be displayed
, the purple diamond on the left is the logo image
Because the role name is long and short, if my logo is in a fixed position, then the logo will be masked by the role nickname
So we can use anchor points to solve this problem.
It is worth noting that my logo is always displayed on the leftmost side of the nickname, so the target reference of my anchor point will be set to Namelabel
This will keep you on the far left.
Of course, depending on your project needs, flexible use
Speaking of which, if you do what I say every step of the way, you'll find that the fonts are very, very big in the scene.
At this point, we set the X, Y, and Z of the playername scale to 0.1.
Why is it 0.1? Because we've magnified the font 10 times times above.
So in order to get the original font size, we have to change the size of the playername. namely: 1/10 = 0.1
Afraid of some small friends to see, nothing, I came up to explain
For example, PlayerName is just an empty object, which is a container for overhead information.
Well, at this point, we've found that the head information is back to its original state, and it's much clearer than it used to be.
We manually enlarge the playername, we find that the larger the value, the larger the font, the smaller the value, the smaller the font
Here's the idea, can we dynamically modify this value by calculating the distance between the character and the camera?
So that no matter how far our camera is from the character, the font remains the size we see.
To prove the idea, we try to write code.
The code is simple, I don't explain it, I don't know the manual.
1 PrivateCamera camera;//Main camera2 PrivateGameobject player;//role3 4 voidStart ()5 {6Camera =Camera.main;7Player = Gameobject.find ("player");8 }9 Ten voidfixedupdate () One { A //calculate the distance between a role and the main camera - Debug.Log (Vector3.distance (player.transform.localPosition, camera.transform.localPosition)); -}
Hang the script on the player and run
In my project, the character and camera are closest to 1.5 and the furthest distance is 3 (this value is only in my project)
That is to say, when the character and camera distance is 1.5, the playername scale is 0.1
What about when the camera is 3 o'clock away? That is: 0.1/1.5 * 3 = current PlayerName scale
OK, write the code, try it.
1 //drag and drop the playername onto a variable after you hang up the script2 Publicgameobject playername;3 4 PrivateCamera camera;//Main camera5 PrivateGameobject player;//role6 7 voidStart ()8 {9Camera =Camera.main;TenPlayer = Gameobject.find ("player"); One } A - voidfixedupdate () - { the //calculate the distance between a role and the main camera - floatDistance =vector3.distance (player.transform.localPosition, camera.transform.localPosition); - - //0.1f/1.5f approximately equal to 0.07f + floatTemscale = Distance *0.07f; - + //the new playername size APlayerName.transform.localScale =NewVector3 (Temscale, Temscale, Temscale); at}
Hang up the script after the run try, how, is it successful?
No matter how you move the camera, the font is always so big.
See here, the above-mentioned image logo know how to solve it
Set the anchor point and magnification on the line, like the font amplification operation, the other without tube
Then the parent object zooms in and the sub-object zooms in!
Now there's a new problem, I use the Hudtext plugin display + XP
Because the magnification is 10 times times the reason, the Hudtext movement is very slow, and the distance is very small
If you don't understand what I'm saying, you can try it out on your own, and it can't be used to explain
The workaround is simple
Adjust the offset curve curve on the hudtext.
This is my own project. I don't have to pack and share, and I don't have much time to start a new project
Because I want to study hard, after years with this demo to Shanghai to find a job, can not find a job is miserable
OK, let's talk about it first, do not understand a few more times, can also give me a message
This article link: http://www.cnblogs.com/shenggege/p/4192797.html
Unity3d role Overhead Information 3d&2d occlusion solution (ii)