Problems with IPointerDownHandler, IPointerUpHandler

Hey!

I got this problem that i have this script and it should detect when i press an UI and then it activates the buttonPressedR and it works in a other scene but when i apply it to another scene and copy everything from it stops working and if i try to write void Start()
in there it doesnt even automatically do the shortcut to it and they dont work any help?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class RightButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
public Rigidbody2D rb;
public Transform Player;
public float speed = 4f;
public bool buttonPressedR;
public void OnPointerDown(PointerEventData eventData)
{
buttonPressedR = true;
}
public void OnPointerUp(PointerEventData eventData)
{
buttonPressedR = false;
}
void Update()
{
if (buttonPressedR == true)
{
Debug.Log(“Works”);
rb.velocity = new Vector2(speed, rb.velocity.y);
Player.transform.localScale = new Vector3(-1, 1, 1);

}
}

}

Add more Debug.Log statements. Place them inside each method. Even put one inside Update outside the if statement.

If you don’t see the one in Update going off, then your gameobject might not be active, or your script isn’t enabled.

If the Update debug prints (the one you add outside the if statement), then make sure your scene has an EventSystem object in it. I believe you can add this from the UI menu fairly easily, but you can also just add the component to an empty gameobject yourself.

The Void Update() works just like start and idk why it seems to work if i put the if (ButtonPressedR = true)
{
Debug.Log(“Works”);
}
it works but yeaah and i got an eventsystem and the gameobjects are unactive or the script.

wait sorry i meant they are active both

So the problem appears to be that the rb,velocity doesnt work the localScale works but the velocity doesnt it works in different scenes and yes i have assigned them

Wait, you’re posting a lot of stuff and I am not sure what is what.
So you have an EventSystem. The script is on an active gameobject that is enabled.
And you mentioned that localScale works, but velocity doesn’t?

I mean, if velocity isn’t working here but it works fine in another scene, you’ll need to figure out what it is you have different between the two scenes on the targeted RigidBody. Are you sure you’re targeting the correct RigidBody?

Its the right one and it still doesnt work last time it didnt work i just did something random and messed with stuff and it started working so im really confused