|
Hey guys, I have a problem with a script. I'm trying to implement that the name of a weapon hovers over it. Here is the script: Btw: WeaponsArray is an array with all of the weapon names. The script works in the way that the name does hover over the weapons. But the problem I have is that there are also names on the mirror side. I mean when I turn around there are names hovering on the positions where the weapons were when you would mirror them on the camera. I searched for this problem and found something but it didn't worked so I hope someone of you can help me.
(comments are locked)
|
|
You really shouldn't use any Find function in OnGUI, as it is called several times per frame. About your problem, isn't there a confusion between 2d and 3d ? What do you mean with confusion between 2d and 3d?
Jun 03 '12 at 08:23 PM
ExTheSea
Don't you expect the names to be on a 3D plane and be reversed when you turn around ? Maybe I misunderstood the mirror thing.
Jun 03 '12 at 08:46 PM
Berenger
The names are not on a plane they are GUI-boxes. I get the position they should have on the screen through Camera.WorldToScreenPoint. With this technique the gui-boxes are on the 2d-screen but are also over the weapons model. So the names are not in the 3d scene just on the 2d gui. The problem I have is that they also appear when I look in the exact opposite direction of the WeaponModel. I hope this clears things up and now someone can help me.
Jun 03 '12 at 09:11 PM
ExTheSea
Ooooook, it's displayed even when the weapon is outside the camera's frustrum. It's strange that the 2D coordinate you find are whithin range, but anyway you can use go.renderer.isVisible before drawing the gui.
Jun 03 '12 at 11:09 PM
Berenger
go.renderer.isVisible worked like a charm and I will change the find thing to something more cpu friendly^^. Big Thanks although it seems you didn't quite understand my entire script :).
Jun 04 '12 at 11:36 AM
ExTheSea
(comments are locked)
|
|
You have to do some kind of convertion from 3D coordinates to 2D point and that is mighty difficult. what you should do instead is put a 3D text object over each weapon and put this script over it to tell it to only appear if the player is a certain distance from it. I got it done with the script which is in the question and go.renderer.isVisible. For the convertion I used Camera.WorldToScreenPoint. This function gives back the screen position a 3d object has. ...but thanks for your answer I maybe use it at another point in my game.
Jun 04 '12 at 12:08 PM
ExTheSea
(comments are locked)
|
