Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Our response to Improbable’s blog post (and why you can keep working on your SpatialOS game). Read more here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

[SOLVED] 2 Player controls?

Discussion in 'Editor & General Support' started by benjamin.magnussen, Oct 23, 2009.

  1. benjamin.magnussen

    benjamin.magnussen

    Joined:
    Oct 22, 2009
    Posts:
    8
    I'm a student doing a small school project game.
    I have very little experience in scripting, so I'm using tutorial scripts for pretty much everything.

    I've used the 2d platform controller to setup 2 characters in my game. I've made alternate inputs for moving and jumping, but how do I connect these in the script? Right now I move both characters simultaneously.
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    If you've already used the Input manager to set up new input axes, you will note that the new axes have different names. The built-in left-right axis is called "Horizontal" - for the second player, it might be called "Horizontal2", say.

    In your code, you just need to look for the Input.GetAxis calls and replace the existing axis name with the new one for the second player. So, if your player 1 script has something like:-
    Code (csharp):
    1. var x = Input.GetAxis("Horizontal");
    ...then your player 2 script might have:-
    Code (csharp):
    1. var x = Input.GetAxis("Horizontal2");
     
    exe_cutable likes this.
  3. benjamin.magnussen

    benjamin.magnussen

    Joined:
    Oct 22, 2009
    Posts:
    8
    Well thank you andeeee.

    I guess it was too obvious for me to see.
     
  4. ProgrammeJava

    ProgrammeJava

    Joined:
    Jan 18, 2016
    Posts:
    2
    @andeeeee Do we make separate scripts? I'm using 3d ThirdPersonController,
    so would I duplicate the script and change that?