Author Topic: Converting GetKeyDown input to UIButton sprite input  (Read 2957 times)

arumiat

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Converting GetKeyDown input to UIButton sprite input
« on: October 21, 2014, 03:40:23 AM »
Hi all

I have a script that currently allows gives me keyboard input to move an object within my scene, like so

  1. public class PlaneMovement : MonoBehaviour {
  2.  
  3.         public float moveSpeed = 10.0f;
  4.        
  5.         // Use this for initialization
  6.         void Start () {
  7.        
  8.         }
  9.        
  10.         // Update is called once per frame
  11.         public void Update () {
  12.        
  13.                 transform.Translate(Vector3.up * Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed);
  14.  
  15.                 if (Input.GetKey (KeyCode.W))
  16.                 {
  17.                         transform.Rotate (Vector3.right, Space.Self);
  18.                 }
  19.  
  20.                 if (Input.GetKey (KeyCode.S))
  21.                 {
  22.                         transform.Rotate (Vector3.left, Space.Self);
  23.                 }
  24.  
  25.  
  26.                 if (Input.GetKey (KeyCode.RightArrow))
  27.                 {
  28.                         transform.Rotate (Vector3.up, Space.Self);
  29.                 }
  30.  
  31.                 if (Input.GetKey (KeyCode.LeftArrow))
  32.                 {
  33.                         transform.Rotate (Vector3.down, Space.Self);
  34.                 }
  35.  
  36.                 if (Input.GetKey (KeyCode.A))
  37.                 {
  38.                         transform.Rotate (Vector3.back, Space.Self);
  39.                 }
  40.  
  41.                 if (Input.GetKey (KeyCode.D))
  42.                 {
  43.                         transform.Rotate (Vector3.forward, Space.Self);
  44.                 }
  45.         }
  46. }

Now I'd like to create an extremely simple interface to test my scene on a tablet device, so just 8 sprites in a line (or even just 1 to start off with), each of which will reference one of the keys above.

I've created the sprites, attached UIButton scripts and colliders and tried writing a new script with individual void functions, each referencing one of the above buttons, but no luck working (i'm testing initially with just the mouse).

Can anyone point me in the direction or provide an example of how I can add to this current code to get the result I'm looking for? I have a feeling it's to do with 'delegates' but the Microsoft explanation on this was far too complicated for me sadly.

Thanks in advance

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Converting GetKeyDown input to UIButton sprite input
« Reply #1 on: October 22, 2014, 05:00:32 AM »
Update() is called once per frame. Button callbacks are called only once -- when you press on them, click on them, or whatever else you chose. I'm guessing you went with the click, which only happens once.