button action in the same controller for local muiltiplayer,Instantiate button action for local multiplayer

Hi guys! i’m trying to use the same script adding to different players. I’ve been creating a simple game like the “space shooter tutorial” and i’m trying to add a local multiplayer and testing the game with 2 ships. I’ve got a playerControler which define the joypad controls for the movement of each whip. It works so i’m trying to add the same thing for the shoot button however when i press the button both the ships shoot!

I used the “tag” string to indentify the ship and for movement works but not for shot.

Here the script:

[System.SerializableAttribute] public class Boundary
{
public float xMin, xMax, zMin, zMax;
}

public class PlayerController : MonoBehaviour {

public float speed;
public float tiltX;

public Boundary boundary;

public GameObject shot;
public Transform shotSpawn;

void Update () {
    if (Input.GetButtonDown("Fire1 " + tag)) **//**DON'T WORKS****
    {
        Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
    }
}

private void FixedUpdate()
{
        SetPlayerData(tag); **//**WORKS****
}

private void SetPlayerData (string tag)
{
    float moveVertical = Input.GetAxis("Vertical " + tag); 
    float moveOrizontal = Input.GetAxis("Horizontal " + tag);

    Vector3 movement = new Vector3(moveOrizontal, 0.0f, moveVertical);
    Rigidbody rigidbody = GetComponent<Rigidbody>();

    rigidbody.velocity = movement * speed;

    rigidbody.position = new Vector3(
        Mathf.Clamp(rigidbody.position.x, boundary.xMin, boundary.xMax),
        0.0F,
        Mathf.Clamp(rigidbody.position.z, boundary.zMin, boundary.zMax)
    );

    rigidbody.rotation = Quaternion.Euler(0.0f, 0.0f, -(rigidbody.velocity.x * tiltX));
}

}

I’m sorry i’m a very beginner. Thanks in advance,Hi guys! i’m trying to use the same script adding to different players. I’ve been creating a simple game like the “space shooter tutorial” and i’m trying to add a local multiplayer and testing the game with 2 ships. I’ve got a playerControler which define the joypad controls for the movement of each whip. It works so i’m trying to add the same thing for the shoot button however when i press the button both the ships shoot!

I used the “tag” string to indentify the ship and for movement works but not for shot.

Here the script:

[System.SerializableAttribute] public class Boundary
{
public float xMin, xMax, zMin, zMax;
}

public class PlayerController : MonoBehaviour {

public float speed;
public float tiltX;

public Boundary boundary;

public GameObject shot;
public Transform shotSpawn;

//public float fireRate;
//private float nextFire = 0.5F;

// Update is called once per frame
void Update () {
    if (Input.GetButtonDown("Fire1 " + tag)) **//**DON'T WORKS****
    {
        Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
    }
}

private void FixedUpdate()
{
        SetPlayerData(tag); **//**WORKS****
}

private void SetPlayerData (string tag)
{
    float moveVertical = Input.GetAxis("Vertical " + tag); 
    float moveOrizontal = Input.GetAxis("Horizontal " + tag);

    Vector3 movement = new Vector3(moveOrizontal, 0.0f, moveVertical);
    Rigidbody rigidbody = GetComponent<Rigidbody>();

    rigidbody.velocity = movement * speed;

    rigidbody.position = new Vector3(
        Mathf.Clamp(rigidbody.position.x, boundary.xMin, boundary.xMax),
        0.0F,
        Mathf.Clamp(rigidbody.position.z, boundary.zMin, boundary.zMax)
    );

    rigidbody.rotation = Quaternion.Euler(0.0f, 0.0f, -(rigidbody.velocity.x * tiltX));
}

}

I’m sorry i’m a very beginner. Thanks in advance

I’m sorry! i’ve just resolved! :slight_smile:

i did’n know that in the inputManager i had to specify the number of the joypad in “Positive Button”! (ex. joystick 1 button 0).

Thanks for evereything! sorry again