Search Unity

Distinguish between player clicks on item entities

Discussion in '2D' started by Ivanskodje, Mar 31, 2015.

  1. Ivanskodje

    Ivanskodje

    Joined:
    Mar 29, 2015
    Posts:
    57
    I am trying to find out a way to distinguish between players by getting the player ID (gameobject?) of whomever is clicking an item and place it into that specific players inventory. My problem is not being able to find out which player is clicking with the mouse (if it was OnEnterCollission it would be easier to find the name of the gameobject entering, thus which player). Anyone have a simple solution for this?

    Appreciate any working solution for this problem, and if you need more information let me know :)

    // -----------------------------
    // Example code of usage:
    //
    void OnMouseEnter()
    {
    // Example
    mouseEnter = true;
    }


    void Update()
    {
    if (Input.GetMouseButtonDown(0) && mouseEnter)
    {
    // Do stuff here and add items to the player that clicked!
    }
    }
     
  2. Ivanskodje

    Ivanskodje

    Joined:
    Mar 29, 2015
    Posts:
    57
    Let me rephrase in case people didn't understand my question;
    "How do I get the specific Player's reference from the player that clicks (Cursor in an 2D environment) an item? (assume there are more than 1 player)"
     
    Last edited: Apr 4, 2015
  3. Ivanskodje

    Ivanskodje

    Joined:
    Mar 29, 2015
    Posts:
    57
    BUMP II
     
  4. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    Is this multiplayer?
     
    Ivanskodje likes this.
  5. Ivanskodje

    Ivanskodje

    Joined:
    Mar 29, 2015
    Posts:
    57
    Correct - Multiplayer. Thus I cannot just search for any player :x
    I have to get input from the player clicking the item somehow...!
     
  6. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    What networking middleware are you using?
     
  7. Ivanskodje

    Ivanskodje

    Joined:
    Mar 29, 2015
    Posts:
    57
    Nothing is set yet - this is preperation for multiplayer implementation, so none specific.
    Any recommendation of networking middleware (I don't even know what that is) is appreciated!
     
  8. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    Photon would be good if you're a beginner. The thing is, every middleware defines players differently so you can't implement this before you know which you're using.

    For example, Photon defines players with the PhotonPlayer class while DarkRift defines players with an integer ID.
     
    theANMATOR2b and Ivanskodje like this.
  9. Ivanskodje

    Ivanskodje

    Joined:
    Mar 29, 2015
    Posts:
    57
    Thanks - I will make sure to get into it before continuing my project :)