- Home /
Question by
justinpatters · Jul 14, 2013 at 03:42 PM ·
androidplayermobileswipe
Falling Character needs its position reset after swipe
Hello! I've found a few scripts which I've copied/pasted/edited and was able to get my test level almost working: a character (which has this script attached to it) is falling. After the player swipes/moves the character in a direction and let's go, I need it to snap back X and Z positions, but not Y. I'm also having an issue just getting unity remote to work with android, so I added a "keypress" command which doesn't register at all. Any help would be appreciated:
private var h : float;
private var v : float;
var horozontalSpeed : float = 1.0;
var verticalSpeed : float = 1.0;
//snap position on y axis
var keepY : float;
var keepX : float;
var keepZ : float;
function Start(){
}
function Update()
{
keepY = transform.position.y;
keepZ = 3.370361;
keepX = -7.483171;
}
if(Input.GetKeyUp("a")){
transform.Translate(keepX, keepY, keepZ, Space.World);
Debug.Log("movingme");
}
if (Input.touchCount == 1)
{
var touch : Touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Moved)
{
h = horozontalSpeed * touch.deltaPosition.x ;
transform.Translate( 0, -h, 0, Space.World );
v = verticalSpeed * touch.deltaPosition.y ;
transform.Translate( v, 0, 0, Space.World );
}
if(touch.phase == TouchPhase.Ended){
transform.Translate(keepX, keepY, keepZ, Space.World);
}
}
function OnGUI () {
GUI.Label (Rect (60,35,100,100), "hoziontal" + h, "box");
GUI.Label (Rect (60,50,100,100), "hspeed" + horozontalSpeed, "box");
GUI.Label (Rect (60,75,100,100), "vspeed" + verticalSpeed, "box");
}
Comment
Answer by dorpeleg · Jul 14, 2013 at 06:51 PM
All your "if" statements are outside of the update function.
Move them inside....