- Home /
Question by
convictcartel · Dec 25, 2013 at 02:18 AM ·
touchjoystickphonemove to
[HELP] Joystick Movement/Button Movement
Im trying to make my 3rd person game work when I press buttons to move my character just as I would with my WASD Control.. but he either goes through the terrain or wont move at all.. please and thank you!!
#pragma strict
public var walk = false;
public var attack = true;
var speed : float = 1.0;
var rotateSpeed : float = 3.0;
var walkspeed: float = 5.0;
function Start () {
}
function Update () {
if (Input.GetButtonDown ("UP")) {
var move: Vector3 = Vector3.forward * 4.0;
transform.Translate(move * Time.deltaTime);
}
}
function Slap ()
{
attack = true;
animation.Play("bitchslap",PlayMode.StopAll);
yield WaitForSeconds(0.75) ;
attack = false;
}
function OnGUI() {
//SLAP Button
if(GUI.Button (new Rect(Screen.width / 2 + 100, Screen.height / 250 + 170 + (10 * 25), 100, 50), "Slap")) {
StopCoroutine("Slap");
StartCoroutine("Slap");
}
//JUMP Button
if(GUI.Button (new Rect(Screen.width / 2 - 90, Screen.height / 250 + 170 + (10 * 25), 160, 50), "JUMP")) {
animation.Play("jump");
rigidbody.AddForce(Vector3.up *speed);
}
//MOVEUP Button
if(GUI.Button (new Rect(Screen.width / 2 - 250, Screen.height / 250 + 90 + (10 * 25), 50, 50), "UP")) {
animation.Play("walk");
}
//MOVEDOWN Button
if(GUI.Button (new Rect(Screen.width / 2 - 250, Screen.height / 250 + 150 + (10 * 25), 50, 50), "DOWN")) {
animation.Play("walk");
}
//MOVERIGHTButton
if(GUI.Button (new Rect(Screen.width / 2 - 190, Screen.height / 250 + 120 + (10 * 25), 50, 50), "RIGHT")) {
animation.Play("walk");
}
//MOVELEFTButton
if(GUI.Button (new Rect(Screen.width / 2 - 310, Screen.height / 250 + 120 + (10 * 25), 50, 50), "LEFT")) {
animation.Play("walk");
}
}
Comment
Your answer
Follow this Question
Related Questions
Please can someone explain how i use the joystick prefab for 2d. 0 Answers
how to make gameobject follow finger touch position within custom joystick 1 Answer
Dual Stick Touch Shooter 0 Answers
Tablet joystick appearing on touch 1 Answer
how i can convert thjs code to touch (Input.anyKeyDown) 2 Answers