- Home /
Does anyone know of a way to assign an Axis or KeyCode to a GUI Button or Texture? I'm trying to make a 2D platformer on a mobile device. As you can tell, I have no Idea what I'm doing...
using UnityEngine; using UnityEngine.UI; using System.Collections;
public class TouchInput : MonoBehaviour { public Canvas touchControl; public Button right; public Button left; public Button jump;
 // Use this for initialization
 void Start () {
     touchControl = touchControl.GetComponent<Canvas> ();
     right = right.GetComponent<Button> ();
     left = left.GetComponent<Button> ();
     jump = jump.GetComponent<Button> ();
     touchControl.enabled = true;
 }
 
 // Update is called once per frame
 public void Jump() {
     Input.GetKeyDown (KeyCode.Space);
 }
}
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by mconradie · Jul 18, 2015 at 07:12 PM
Something like this should work
 void Update() {
     if (Input.GetKeyDown(KeyCode.Space)) {
         jump.SendMessage("OnClick");
     }
 }
Your answer
 
 
             Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
How can i make a sprite move in the direction it is rotated? 1 Answer
Place UI element on pointer up position. 1 Answer
Unlocking & "Equipping" Colors onto Sprites with c# 2 Answers
transform.Translate moves the object too slow in ipad 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                