He guys.
I’m working on a GUI texture that needs to move on a click. Now basicly I got the thing moving in a static resolution, but my client needs it to be a dynamic resolution. (Both the trigger script shown here, aswell as the MoveObject script are from the wiki)
What i came up with now (the working script :p)
In this situation the object is just moving fine.
var normalTexture:Texture;
var hoverTexture:Texture;
var pressedTexture:Texture;
private var state = 0;
private var state2 = 0;
private var myGUITexture:GUITexture;
myGUITexture = GetComponent (GUITexture);
function OnMouseEnter(){
state++;
if (state == 1) myGUITexture.texture = hoverTexture;
}
function OnMouseDown(){
state++;
if (state == 2) myGUITexture.texture = pressedTexture;
}
function OnMouseUp(){
if (state == 2){
state--;
state2++;
if (state2 == 1){
yield MoveObject.use.Translation(transform, Vector3(-0.25, 0.875, 0.0), Vector3(0, 0.875, 0.0), 0.25, MoveType.Speed);
}else{
yield MoveObject.use.Translation(transform, Vector3(0, 0.875, 0.0), Vector3(-0.25, 0.875, 0.0), 0.25, MoveType.Speed);
state2 = 0;
}
}else{
state--;
if (state < 0) state = 0;
}
myGUITexture.texture = normalTexture;
}
function OnMouseExit(){
if (state > 0) state--;
if (state == 0) myGUITexture.texture = normalTexture;
}
Now to get it working on a dynamic resolution I added a line to calculate the x Postion relative to the resolution and store it in var xlocA. After that i changed the “-0,25” value of the MoveObject call into the var xlocA. The whole thing resulting in this script:
var normalTexture:Texture;
var hoverTexture:Texture;
var pressedTexture:Texture;
private var state = 0;
private var state2 = 0;
private var xlocA:int = (-200/Screen.width);
private var myGUITexture:GUITexture;
myGUITexture = GetComponent (GUITexture);
function OnMouseEnter(){
state++;
if (state == 1) myGUITexture.texture = hoverTexture;
}
function OnMouseDown(){
state++;
if (state == 2) myGUITexture.texture = pressedTexture;
}
function OnMouseUp(){
if (state == 2){
state--;
state2++;
if (state2 == 1){
yield MoveObject.use.Translation(transform, Vector3(xlocA, 0.875, 0.0), Vector3(0, 0.875, 0.0), 0.25, MoveType.Speed);
}else{
yield MoveObject.use.Translation(transform, Vector3(0, 0.875, 0.0), Vector3(xlocA, 0.875, 0.0), 0.25, MoveType.Speed);
state2 = 0;
}
}else{
state--;
if (state < 0) state = 0;
}
myGUITexture.texture = normalTexture;
}
function OnMouseExit(){
if (state > 0) state--;
if (state == 0) myGUITexture.texture = normalTexture;
}
Now the problem is that it wont move. Played around a bit wih the vars and movement on other angles is no problem. The only problem is that the var gets turned into 0 all the time. Anybody got a clue:face_with_spiral_eyes: