- Home /
One Rect in 2 different places
Hello, i wanted to make buttons to move player. Its working but iam using one rect for drawing button and the same with .contain to check if this button is pressing. The problem is that button is drawing on "bot" of screen( as i wanted ) but touching area i reacting on "top" of screen( just on opposite side ). Here is code:
public class PlayerController : MonoBehaviour {
public GUISkin gui_skin_uparrow;
public GUISkin gui_skin_rightarrow;
public GUISkin gui_skin_leftarrow;
private Rect ArrowUP= new Rect(Screen.width-160,Screen.height-120,120,120);
private Rect ArrowLEFT=new Rect(0,Screen.height-120,120,120);
private Rect ArrowRIGHT=new Rect(120,Screen.height-122,120,120);
private bool direct_changed=false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI ()
{
foreach ( Touch t in Input.touches )
{
if( ArrowLEFT.Contains( t.position ) ){ transform.Rotate(Vector3.forward* 1 ); direct_changed=true;}
if( ArrowRIGHT.Contains( t.position ) ){ transform.Rotate(Vector3.forward* -1 ); direct_changed=true;}
if( ArrowUP.Contains( t.position ) )
{
if( !direct_changed )
{
transform.Translate(2*Time.deltaTime,0,0);
}
else
{
transform.Translate(3*Time.deltaTime,0,0);
}
}
}
GUI.skin=gui_skin_uparrow;
if( GUI.RepeatButton ( ArrowUP/*new Rect(Screen.width-160,Screen.height-120,120,120)*/, "go go" ) )
{
//transform.Translate(2 * Time.deltaTime,0,0);
}
GUI.skin=gui_skin_leftarrow;
if( GUI.RepeatButton ( ArrowLEFT )
{
//transform.Rotate(Vector3.forward* 1 );
}
GUI.skin=gui_skin_rightarrow;
if( GUI.RepeatButton ( ArrowRIGHT, "go go" ) )
{
//transform.Rotate(Vector3.forward* -1 );
}
direct_changed=false;
}
}
So what can i do to fix it?
Comment