- Home /
TWO GUI texture that doesn't work together
I have two GUITexture that move left and right a cube. Is pretty strange but together they don't work. If I activate only one it works. To be more specific: If I have the left GUItexture alone in the game the cube move left. If I have the right GUITexture activated alone the cube move right. Seems all fine I thought but If I have both of them the cube move only right and not left. Where is the mistake?
Here is the code inside the GameObject cube for Right move
void OnMousedown () {
transform.position += Vector3.right * Time.deltaTime;
For Left move
void OnMousedown () {
transform.position += Vector3.left * Time.deltaTime;
And this is the left GUITexture code
void Update ()
{
//is there a touch on screen
if (Input.touches.Length <= 0)
{
//if there is no touches on the screen the this code
return;
}
else // if there is a touch
{
//loop through all the touches on the screen
for(int i = 0 ; i < Input.touchCount; i++)
{
//execute this code for current touch (i) on the screen
if(this.guiTexture.HitTest(Input.GetTouch(i).position))
{
//if current hits our GUITexture, run this code
if(Input.GetTouch (i).phase == TouchPhase.Began)
//move the cube
Cube.GetComponent<Left>().enabled = true;
left.transform.position += Vector3.left * Time.deltaTime;
}
if(Input.GetTouch (i).phase == TouchPhase.Ended)
{
return;
}
if(Input.GetTouch(i).phase == TouchPhase.Stationary);
//if current finger is stationary run this code
{
Cube.GetComponent<Left> ().enabled = true;
left.transform.position += Vector3.left * Time.deltaTime
This is the right GUITexture code
void Update ()
{
//is there a touch on screen
if (Input.touches.Length <= 0)
{
//if there is no touches on the screen the this code
return;
}
else // if there is a touch
{
//loop through all the touches on the screen
for(int i = 0 ; i < Input.touchCount; i++)
{
//execute this code for current touch (i) on the screen
if(this.guiTexture.HitTest(Input.GetTouch(i).position))
{
//if current hits our GUITexture, run this code
if(Input.GetTouch (i).phase == TouchPhase.Began)
//move the cube
Cube.GetComponent<Left>().enabled = true;
right.transform.position += Vector3.right * Time.deltaTime;
}
if(Input.GetTouch (i).phase == TouchPhase.Ended)
{
return;
}
if(Input.GetTouch(i).phase == TouchPhase.Stationary);
//if current finger is stationary run this code
{
Cube.GetComponent<Left> ().enabled = true;
right.transform.position += Vector3.right * Time.deltaTime;
}
What is the reason for this? Why they don't work together meaning when I push the left gui texture the cube moves left and when I push the right guitexture the cube move right
I hope someone can help me. I really have no clue and did search all day about this
CL
Hello Robertbu, I have included the full code for the the left and right GUItexture. IN theory when I push the GUItexture should move the cube left if I push the left GUITexture and and right if I push the right GUItexture . But as I said they work well only when they are not together meaning only one of them. The script inside the cube named Left and Right was already all of it therefore I didn't updated.any idea why?
I don't see the problem. There is one potential issue. You state you use:
void On$$anonymous$$ousedown
But you misspelled the name of the callback. It is On$$anonymous$$ouseDown(), so this callback is not being called. But I'm confused about the use of this function at all. Usually you would only use On$$anonymous$$ouseDown() or HitTest() but not both. But based on your description, this is not the base of your movement problem.
Thank you. It made all the difference. Again thank you CL