How to Control a GameObject with A UI element?

Hey guys, nooby dev here. I’ve been sitting here for hours trying to get his dang thing to work. Here’s the gist:

I want this space ship to move left,

When I press this text button.

Problem is, I can’t seem to find a way to “connect” the UI element with the GameObject.

Here’s my code:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class FindScript : MonoBehaviour {

private GameObject ship;
	void Start () {
		ship = GameObject.Find ("SSpaceship1"); //Finding the space ship

	public void Update() {
		ship.rigidbody2D.AddForce(new Vector2(-12, 0));


I got nothin’. Can anyone here please be kind enough to point me where I’m going wrong with this?

Thanks in advance.

Is your “arrow button” a UI button, image, or something else? If it’s just an image, you could try using something like this:

bool canMove;

void FixedUpdate() {
ship.rigidbody2D.AddForce(new Vector2(-12, 0));


void OnMouseDown() {
canMove = true;

void OnMouseUpAsButton() {
canMove = false;

If it’s a button from the new UI in 4.6, you could try using the new events and event triggers in 4.6 to basically call a function you create similar to OnMouseDown() above and just set canMove to true. You will also need to know when you let go of the button.

Excuse me for the poor answer.