Reputation: 83
I'm making an Android game, I assigned public onClick
functions to three buttons on the canvas and they're not working on my Android Phone or by clicking them on my computer. Here's what it looks like:
And here is my code for the ball, as you can see I'm trying to make the ball move forward with the ForwardSLASHleft
function, backwards with the BackwardsSlashRight
function, and start with the StartButton
function. But none of them are working.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class ballScript : MonoBehaviour {
Rigidbody rb;
public float thrust;
public Button left;
public Button right;
public Button startB;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody>();
gameObject.SetActive(false);
}
// Update is called once per frame
void Update () {
gameObject.SetActive(true);
}
public void StartButton()
{
gameObject.SetActive(true);
left.enabled = true;
right.enabled = true;
startB.enabled = false;
}
public void forwardSLASHleft()
{
rb.AddForce(transform.right * -1 * thrust);
}
public void backwardsSLASHright()
{
rb.AddForce(transform.right * 1 * thrust);
}
}
Upvotes: 0
Views: 1056
Reputation: 650
Drag your script to your Buttons Onclick component and select your function
Also make sure that you have EventSystem GameObject
Upvotes: 1