Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

where am I going wrong in this OnPointerDown script?

Discussion in 'Scripting' started by JDVDeisgn, Sep 15, 2016.

Thread Status:
Not open for further replies.
  1. JDVDeisgn

    JDVDeisgn

    Joined:
    Oct 17, 2015
    Posts:
    148
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.EventSystems;
    4.  
    5. public class phgs : MonoBehaviour, IPointerDownHandler {
    6.  
    7.     // Use this for initialization
    8.     void Start () {
    9.    
    10.     }
    11.    
    12.     // Update is called once per frame
    13.     void Update () {
    14.    
    15.     }
    16.  
    17.     public void OnPointerDown(PointerEventData data){
    18.         Debug.Log ("OnPointerDown");
    19.         ph.g = 1;
    20.     }
    21. }
    I've only used buttons via the hierarchy before but now I'm making more advanced stuff that option was very limiting so wanting to do it via coding. if someone could help me out, thanks
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    well the class name is totally non descriptive... and what is "ph.g" supposed to be? it's not declared in the script so you should be seeing errors in the console.

    oh and have you added an appropriate raycaster component to the camera?
     
    CaptainMurphy and CrymX like this.
  3. JDVDeisgn

    JDVDeisgn

    Joined:
    Oct 17, 2015
    Posts:
    148
    I mean it's pretty clear that it's referencing a static float from another script
     
  4. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,139
    Putting aside the bad naming of classes, you gave so little info that we can't really help you solve this. Don't know what type of object this class is on. While I can assume your issue is your debug isn't printing, that is the limit of knowledge I have.
     
    CaptainMurphy and CrymX like this.
  5. JDVDeisgn

    JDVDeisgn

    Joined:
    Oct 17, 2015
    Posts:
    148
    I asked a very simple question, I want it to detect that the button is pressed down, which anyone of any vague knowledge of unity would be able to assume.

    bad naming haha wow you really have no idea at all about coding and professional naming of classes. you probably name them "Script Which Makes The Character Move Forward". I professionally name my scripts as acronyms. I work for a gaming company, very, very standard practise, not that you would know in any way at all
     
  6. JDVDeisgn

    JDVDeisgn

    Joined:
    Oct 17, 2015
    Posts:
    148
    I'm sorry that you can't read into basic, basic professional coding but it's not a good idea to be aggressive (in the case, you not having very advanced knowledge at all of unity) to people because you have issues in your own life

    then again, many on this board won't ever be professional and have no basic perceptive understanding of most things required to work in the industry
     
    Last edited: Sep 15, 2016
  7. CrymX

    CrymX

    Joined:
    Feb 16, 2015
    Posts:
    179
    CaptainMurphy likes this.
  8. CaptainMurphy

    CaptainMurphy

    Joined:
    Jul 15, 2014
    Posts:
    746
    Read through his post history. "Professional" is not the word I would use.

    I was going to respond with the, roughly, 5 ways of getting a button press but I am not professional enough to answer your question.
     
    passerbycmc and CrymX like this.
  9. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,139
    I happen to work in this industry. And in doing so, I try not to assume anything. It is up to you to be clear about what you need help with.

    Issues in my life? huh?

    But, as you are a "pro" and you don't think any of us are, you obviously don't need any help from us.
     
    CrymX and CaptainMurphy like this.
  10. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,738
    You have not explained if this is for 2d objects 3d objects or if it is for the UI system and a canvas. For any of these you will need to add the appropriate Raycaster for the type of object you are trying to interact with to the camera, or in the case of a canvas in overlay mode to the canvas. You also need to have a EventSystem component somewhere in your scene.

    P.S. There are a few industry veterans in here, and i think most agree the naming conventions should convey what things actually are and put readability above all else. People were confused about your static variable `ph.g` because the convention for most languages including C# is to Capitalize the first letter of class names.

    Also stop acting like a tool.
     
    Last edited: Sep 15, 2016
  11. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Yeah - that's a great way to get your questions answered.....
     
    passerbycmc and CaptainMurphy like this.
  12. Buhlaine

    Buhlaine

    Community Manager

    Joined:
    Feb 5, 2016
    Posts:
    348
    I've closed this thread. Thank you to those trying to help the OP, but there is no acceptable reason to shame or antagonize users. I've issued warnings to all parties involved.

    Something that will help reduce threads that devolve like this is to make sure you have sufficient information for users to go off of. A simple "Why doesn't this work" won't get you the best results. Remember that as well as the Developer Network Rules in future posts.
     
    ThermalFusion and CaptainMurphy like this.
Thread Status:
Not open for further replies.