using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerSwap : MonoBehaviour
{
    private InputControls inputControls;
    private InputActionMap currentActionMap;

    public PlayerSwap anotherSwap;
    public AudioSource source;
    public AudioClip soundToPlay;

    private void Awake()
    {
        inputControls = new InputControls();
        PlayerInput playerInput = GetComponent<PlayerInput>();
        currentActionMap = playerInput.currentActionMap;
    }

    void Start()
    {
        currentActionMap.FindAction("Swap").started += _ => Swap();
    }

    void Swap() 
    {
        Vector3 tempPosition = gameObject.transform.position;
        gameObject.transform.position = anotherSwap.gameObject.transform.position;
        anotherSwap.gameObject.transform.position = tempPosition;
        PlaySwapSound();
    }

    void PlaySwapSound() 
    {
        source.PlayOneShot(soundToPlay);
    }
}
