Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Player 2's controls

Discussion in '2D' started by hasen, Apr 24, 2015.

  1. hasen

    hasen

    Joined:
    Apr 1, 2015
    Posts:
    29
    Player 1's controls seem to be all already defined, I simply open project settings -> input and change them to which keys I need, but there don't seem to be any keys for Player 2. Are they already set up to control a second character and if so how do I define the keys? Thanks.
     
  2. hasen

    hasen

    Joined:
    Apr 1, 2015
    Posts:
    29
    Well I managed to solve it in the end anyway.
     
  3. MoonJellyGames

    MoonJellyGames

    Joined:
    Oct 2, 2014
    Posts:
    331
    Care to share how? I'm playing around with a local two-player game (a little bit like Starwhal or Mount Your Friends) and I'll eventually need to support two Dualshock3 controllers. Currently I have one working, but I couldn't get the second one working. I didn't spend much time trying as I'm not really *there* yet, but when the time comes it would be great to have a bit of a reference. :)
     
  4. hasen

    hasen

    Joined:
    Apr 1, 2015
    Posts:
    29
    Yes ok, it may be not the most ideal method but its the way I got it working anyway. I just used keys so I don't know about dual shock controllers. Anyway, each player needs its own controller script and you need to make another set of keys in the code for that and also add those keys in the Unity control preferences too. Then its important to note for movement you need GetAxis("Horizontal2"); for the second player and also need to make Horizontal2 in the Unity control preferences.
     
    theANMATOR2b likes this.
  5. MoonJellyGames

    MoonJellyGames

    Joined:
    Oct 2, 2014
    Posts:
    331
    Okay, that's pretty much what I thought I'd have to do. Although I wonder if you really need two separate scripts for each player with only the input conditions changed, or if you could just contain all control input in an if-statement that checked if the object is player1 or player2.
     
  6. hasen

    hasen

    Joined:
    Apr 1, 2015
    Posts:
    29
    Yeah that's what I thought but how can you check if the object is player 1 or 2? They don't seem to have any IDs that I can see.
     
  7. MoonJellyGames

    MoonJellyGames

    Joined:
    Oct 2, 2014
    Posts:
    331
    You would have to make one. Just make a public int that you can set in the inspector.