No matter which button I press all methods are called
void Update(){
if (Input.GetMouseButton (0)){
RaycastHit2D hit = Physics2D.Raycast (Camera.main.ScreenToWorldPoint (Input.mousePosition), Vector2.zero);
if(hit.collider != null){
Move.Right();
Debug.Log("right button");
}
Heres my script with void right
public void Right (){
GetComponent<Rigidbody2D>().velocity = RightForce;
//GetComponent<Rigidbody2D>().AddForce(RightForce);
Debug.Log ("moveScript was called succesfully");
if(spriterenderer.sprite == sprite2){
spriterenderer.sprite = sprite1;
}
}
public void Left(){
GetComponent<Rigidbody2D> ().AddForce (leftforce);
if(spriterenderer.sprite == sprite1){
spriterenderer.sprite = sprite2;
}
}
public void Jump(){
if (grounded) {
GetComponent<Rigidbody2D> ().AddForce (Jumpforce);
}
}
public void Shoot(){
//Instantiate(bullets
}
}
Heres my script for the left button
void Update () {
if (Input.GetMouseButton (0)) {
///Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
//RaycastHit hit;
//if (Physics.Raycast (ray, out hit) && hit.collider.gameObject.name == "MoveLeft") {
RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
if( hit.collider != null){
Move.Left ();
}
I also want this to be mobile compatible is this possible. Also I should mention I don’t even have to touch near the buttons.