- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
buxton4life · Jul 30, 2012 at 08:18 PM ·
iostouchguitexturetransformsz
Altering Z position of guiTexture through code IOS?
Just wondering why this code does not work, I am trying to move the guiTextures z position from 3 to 0, so the other guiTexture (GUITexture[1]) appears in front of this one when the user taps the screen. Any help would be much appreciated!
var myTextures : GUITexture[] = new GUITexture[3];
function Update(){
for (var evt : Touch in Input.touches)
{
var ft = myTextures[0].HitTest(Input.mousePosition);
var ft2 = myTextures[1].HitTest(Input.mousePosition);
var ft3 = myTextures[2].HitTest(Input.mousePosition);
if (evt.phase == TouchPhase.Stationary)
{
if(ft){
myTextures[0].transform.position = new Vector3(0.5, 0.5, 0);
}
if(ft2){
......./
}
if(ft3){
......./
}
}
}
}
Comment
Best Answer
Answer by ScroodgeM · Jul 30, 2012 at 09:55 PM
may be you need to use 'evt.position' instead of 'Input.mousePosition' ?
bonus:
Toucher.cs
using UnityEngine; using System.Collections; public class Toucher : MonoBehaviour { public GUITexture[] myTextures; void Update() { foreach (Touch evt in Input.touches) { for (int i = 0; i < myTextures.Length; i++) { Vector3 position = myTextures[i].transform.position; position.z = myTextures[i].HitTest(evt.position) ? 3f : 0f; myTextures[i].transform.position = position; } } } }
cheers for the reply, the actual tap bit of the code works fine. I changed transform to destroy and it successfully destroys when tapped. But when I use transform.position it doesn't seem to do anything?