using UnityEngine;

public class P7PlaceCharacterOnTable : MonoBehaviour
{
    public GameObject characterPrefab; // Drag the character prefab here in Inspector
    private GameObject placedCharacter;

    private Vector3 spawnPosition = new Vector3(-9.01f, 22.3f, 7.27f); // Fixed position on the table

    void Update()
    {
        if (Input.GetMouseButtonDown(0)) // Left mouse click
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                Debug.Log("Ray hit: " + hit.collider.name); // Logs what was hit

                if (hit.collider.CompareTag("Table")) // Ensure the table is tagged correctly
                {
                    Debug.Log("Table was clicked!");

                    if (placedCharacter == null)
                    {
                        // Spawn the character at the fixed position on the table
                        placedCharacter = Instantiate(characterPrefab, spawnPosition, Quaternion.identity);
                        Debug.Log("Character placed at: " + spawnPosition);
                    }
                    else
                    {
                        Debug.Log("Character already placed.");
                    }
                }
            }
        }
    }
}
