- Home /
converting standalone code to work on android
hey all.
i am new to scripting and i am making a game for mobile devices. i have made a very basic ladder script with the help of youtube. it works well with a standalone (using up and down arrows to move up and down the ladder) but i would like to put it into an android game so that when you touch a button you can go up it and when you let go of the button you fall back down.
my question is how would i rewrite the script to work with button touch, i have tried using getbuttondown instead of getkeydown but when i do this the character only moves a tiny bit and doesnt go up the ladder at all.
any help would be greatly appreciated :)
this is my script
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Ladder : MonoBehaviour {
public float speed = 6;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerStay2D(Collider2D other)
{
if (other.tag == "Player" && Input.GetKey (KeyCode.UpArrow)) {
other.GetComponent<Rigidbody2D> ().velocity = new Vector2 (0, speed);
} else if (other.tag == "Player" && Input.GetKey (KeyCode.DownArrow)) {
other.GetComponent<Rigidbody2D> ().velocity = new Vector2 (0, -speed);
} else
{
other.GetComponent<Rigidbody2D> ().velocity = new Vector2 (0, 1);
}
}
}
Answer by Ginxx009 · Nov 28, 2017 at 10:08 AM
That code will only work on a standalone platform.
Here's for Mobile For Mobile Movement
Your answer
Follow this Question
Related Questions
Calling script functions from other objects doesn't work on mobile but it does in the editor 2 Answers
How to implement listeners in unity3d android plugin? 0 Answers
Connection failed - android to editor/standalone 1 Answer
Prefab is spawned two times in a row 0 Answers
Android control of two objects. 0 Answers