• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Medija · Apr 01, 2017 at 07:17 AM · androidinput manager

OnPointerDown and OnPointerUp not working

I'm working on my first game ever (first of many :D). I'm targeting the android platform. I have managed to put together the basic mechanism of the game. For the input I'm using a simple UI image as a button to rotate constantly, while holding the button, the player to left relatively to Space.World. I used a Debug.Log and it seems to print my messages on the console but however it doesn't change the status of a boolean variable in order to trigger the rotation. Please help me I'm really stuck for more than two days now. I know it's probably so easy but I'm a total rookie.

Here is my code:

Player Script:

 using UnityEngine;
 
 public class Player : MonoBehaviour
 {
     private float _turnSpeed = 150f;
 
     private bool _turnLeft;
 
     private void FixedUpdate()
     {
         TurnLeft(_turnLeft);
     }
 
     private void OnCollisionEnter()
     {
         Destroy(gameObject);
     }
 
     private void TurnLeft(bool turn)
     {
         if (turn)
         {
             transform.Rotate(-Vector3.up * _turnSpeed * Time.deltaTime, Space.World);
         }
     }
 
     public void OnClicked()
     {
         _turnLeft = true;
     }
 
     public void OnReleased()
     {
         _turnLeft = false;
     }
 }
 

Button Script:

 using UnityEngine;
 using UnityEngine.EventSystems;
 
 public class Button : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
 {
     [SerializeField] private Player _car;
 
     public void OnPointerDown(PointerEventData eventData)
     {
         _car.OnClicked();
         Debug.Log("I'm clicked");
     }
 
     public void OnPointerUp(PointerEventData eventData)
     {
         _car.OnReleased();
         Debug.Log("I'm released");
     }
 }
 

Spawner Script:

 using UnityEngine;
 
 public class Spawner : MonoBehaviour
 {
     [SerializeField] private Player _car;
 
     private Player _spawn;
 
     private Vector3 _instantiatePosistion;
     private Quaternion _instantiateRotation;
 
     private void Start()
     {
         _instantiatePosistion = _car.transform.position;
         _instantiateRotation = _car.transform.rotation;
     }
 
     private void Update()
     {
         if (_spawn != null) return;
         _spawn = Instantiate(_car, _instantiatePosistion, _instantiateRotation);
     }
 }
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Akshay_ROG · Nov 24, 2020 at 07:00 AM

For anyone coming here, this is the solution: (You have to add #region and #regionend before and after the PointerEvent Function)

public class PointerTest : MonoBehaviour, IPointerDownHandler //(or any pointer event handler) #region IPointerDownHandler implementation public void OnPointerDown(PointerEventData eventData) { Debug.Log("This works perfect"); } #regionend

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

4.6.1p2: touch or box collider 0 Answers

Android building error 3 Answers

Hi, I uploaded my Android game on the PlayStore as a AAB using the ARMv7 and ARM64 architectures, but the scenes wont load? What I should fix now? 0 Answers

How to stop a video using the OCULUS script MoviePlayerSample.CS. 0 Answers

How To Get UnitySurfaceView Or The View Rendered? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges