- Home /
Unity iPhone 2D Left Right movement
Hello
I have been trying to get familiar with the Unity iPhone input methods for a while now. I've looked at the examples,docs, and used the SideScrollControl script from the 2D Prefab, but it seems pretty complex.
What I am trying to do is setup a left and right arrow to move a character controller along the X axis (similar to Zombieville controls) with GUITextures. I haven't had much success with it so far, I can get him to move, but I have to keep pressing the button, it doesn't continue to slide along the screen when the button is pressed. Also my fire button will not work when I'm moving, and vice versa, so only one button input is being detected.
var Player: Transform;
var speed : float =1;
var recoveryTime = 10;
private var delay = 0;
function Update () { if(Input.touchCount == 1){ var currentTouch:Touch = Input.touches[0];
if(currentTouch.phase == TouchPhase.Began && guiTexture.HitTest(currentTouch.position)){ Player.Translate(speed*Time.deltaTime,0,0);
}
}
}
Does it make any sense to use a character collider with the Move function, instead of Transform.Translate, then try to convert the following script to iPhone compatible?
var speed : float = 6.0;
var jumpSpeed : float = 8.0; var gravity : float = 20.0;
private var moveDirection : Vector3 = Vector3.zero;
function Update() { var controller : CharacterController = GetComponent(CharacterController); if (controller.isGrounded) { // We are grounded, so recalculate // move direction directly from axes moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed;
if (Input.GetButton ("Jump")) { moveDirection.y = jumpSpeed; } }
// Apply gravity moveDirection.y -= gravity * Time.deltaTime;
// Move the controller controller.Move(moveDirection * Time.deltaTime);
}
Any suggestions about how to do this would be greatly appreciated.
Thanks
Your answer
Follow this Question
Related Questions
How to export .ipa from Unity? 2 Answers
Input in editor scripts 2 Answers
Keyboard Input Problem 1 Answer
Boolean and input relation 0 Answers