Button onclick problem.
So, I am making a doodle jump game. I have added left and right movement with left and right arrow keys on the keyboard, but now I created 2 buttons that are taking the whole screen, one is on the left half, and one is on the right half. When I click the left one, I want the player to move left and when I click the right one the player moves to the right. I have copied the code that moves the player and have pasted it inside a public void and assigned it for onclick function in unity. Here is the moving script for arrows:
void FixedUpdate ()
{
if (Input.GetKey (KeyCode.LeftArrow) || Input.GetKey (KeyCode.A))
{
this.gameObject.transform.Translate (Vector3.left * Time.deltaTime * speed);
}
else if (Input.GetKey (KeyCode.RightArrow) || Input.GetKey (KeyCode.D))
{
this.gameObject.transform.Translate (Vector3.right * Time.deltaTime * speed);
}
}
But when I copy it in my script for buttons it doesn't work!
using UnityEngine;
using System.Collections;
public class LeftButton : MonoBehaviour {
float speed = 4f;
public GameObject player;
public void LeftMovement()
{
this.gameObject.transform.Translate (Vector3.left * Time.deltaTime * speed);
Debug.Log ("Touched!");
}
public void RightMovement()
{
this.gameObject.transform.Translate (Vector3.right * Time.deltaTime * speed);
Debug.Log ("Touched243!");
}
}
I have assigned everything correctly, that is for sure. Please help me repair the problem. Here is a screenshot with buttons! Please help me!
Your answer
Follow this Question
Related Questions
Where can I learn C# 3 Answers
} expected Type or namespace definition, or end-of-file expected, Basic Clicker 0 Answers
Can't Figure Out How To Make Bounce Pad 0 Answers
Tanks Tutorial Image separating 0 Answers