- Home /
Question by
Jordi · Oct 13, 2010 at 06:12 PM ·
worldtoscreenpoint
Camera Relative Screen Pixel-coordinates
I've been trying to set up a Domino-Line (parent object) with 5 Dominos in it (Children). When mousing over the Domino-Line, I want two UI-elements to show up: A '-' sign behind the first domino in line, and a '+' behind the last in line.
However, when trying to use WorldToScreenPoint, the UI-elements get placed all wrong, to the left of the entire line above eachother.
So how would I fix this?
EDIT: Here's part of the code, the OnGUI function
void OnGUI() { if (playScript.gamePlays == false) { if (mouseOver == true) {
Vector3 screenPosBegin = Camera.main.WorldToScreenPoint(transform.TransformPoint(firstStone.transform.localPosition));
Vector3 screenPosEnd = Camera.main.WorldToScreenPoint(transform.TransformPoint(lastStone.transform.localPosition));
if (amountOfStones > minStones) {
if (GUI.Button(new Rect(screenPosBegin.x, Camera.main.pixelHeight - screenPosBegin.y, 50 * (1.1f - (screenPosBegin.z/20)), 50 * (1.1f - (screenPosBegin.z/20))), detractStoneTex)) {
amountOfStones--;
Destroy(lastStone);
touchBox.size = new Vector3( (amountOfStones * 0.5f) - 0.5f, 0.6f, 0.4f);
touchBox.center = new Vector3( touchBox.size.x/2, 0, 0);
}
}
if (amountOfStones < maxStones) {
if (GUI.Button(new Rect(screenPosEnd.x, Camera.main.pixelHeight - screenPosEnd.y, 50 * (1.1f - (screenPosBegin.z/20)), 50 * (1.1f - (screenPosBegin.z/20))), addStoneTex)) {
amountOfStones++;
GameObject newStone = Instantiate( Resources.Load("Domino"), Vector3.zero, Quaternion.identity) as GameObject;
newStone.transform.parent = transform;
newStone.transform.localPosition = new Vector3((amountOfStones * 0.5f) - 0.5f, 0, 0);
newStone.transform.localRotation = Quaternion.identity;
touchBox.size = new Vector3( (amountOfStones * 0.5f) - 0.5f, 0.6f, 0.4f);
touchBox.center = new Vector3( touchBox.size.x/2, 0, 0);
}
}
}
}
}
Right now I've made it to look -sorta- ok, by subtracting the height from it.
Comment
Could you post some code so that we can see what might be wrong?
Your answer
![](https://koobas.hobune.stream/wayback/20220613075540im_/https://answers.unity.com/themes/thub/images/avi.jpg)