to get the 2d coordinates of my “Tower” which i will then use to draw a rectangle at that position. Can someone help me? Where I do put in the tower object? How do I get the coordinates of my tower object? Thanks,
I guess the tower’s position doesn’t change, so you could easily do this in the Start() function, so you don’t keep calling the search function which takes a lot of useage of the device.
For determination of coordinates on the screen you use function WorldToScreenPoint(). But don’t forget that it gives pivot point coordinates. In your case - the cylinder center. Furtherfor the health bar display, you can use either GUITexture, or GUIElements inOnGUI(). I wrote GUITexture example below (attach this script at your tower):
public GUITexture myhb = null; //your health bar for tower
void Start() {
setPosScr();
}
void Update() {
setPosScr();
}
public void setPosScr() {
Vector3 screenPos = Camera.WorldToScreenPoint(this.transform.position);
myhb.pixelInset = new Rect(screenPos.x, Screen.height - screenPos.y, myhb.pixelInset.width, mybh.PixelInset.height);
}