diff --git a/Assets/Scripts/CardPositionManager.cs b/Assets/Scripts/CardPositionManager.cs new file mode 100644 index 0000000..ac76248 --- /dev/null +++ b/Assets/Scripts/CardPositionManager.cs @@ -0,0 +1,95 @@ +using UnityEngine; + +public class CardPositionMannager : MonoBehaviour +{ + public GameObject player1; + public GameObject player2; + public GameObject closeCard1; + public GameObject closeCard2; + + // Define the positions where you want the objects to be placed + private Vector3 player1Position = new Vector3((float)-4.5, 5, 0); + private Vector3 player2Position = new Vector3((float)-4.5, -5, 0); + private Vector3 closeCard1Position = new Vector3(-2, (float)1.2, 0); + private Vector3 closeCard2Position = new Vector3(-2, (float)-1.2, 0); + + void Start() + { + Debug.Log("Starting CardPositionMannager"); + + // Set the positions of the parent objects + SetGlobalPosition(player1, player1Position, "Player 1"); + SetGlobalPosition(player2, player2Position, "Player 2"); + SetGlobalPosition(closeCard1, closeCard1Position, "Close Card 1"); + SetGlobalPosition(closeCard2, closeCard2Position, "Close Card 2"); + + // Position the individual cards within each parent + PositionCardsLocally(player1, 1.5f, "Player 1"); + PositionCardsLocally(player2, 1.5f, "Player 2"); + PositionCardsLocally(closeCard1, 1.5f, "Close Card 1"); + PositionCardsLocally(closeCard2, 1.5f, "Close Card 2"); + } + + void SetGlobalPosition(GameObject obj, Vector3 position, string name) + { + if (obj != null) + { + obj.transform.position = position; + Debug.Log($"{name} positioned at {position} globally"); + } + else + { + Debug.LogError($"{name} is not assigned!"); + } + } + + void PositionCardsLocally(GameObject parent, float spacing, string parentName) + { + if (parent != null) + { + for (int i = 0; i < parent.transform.childCount; i++) + { + Transform child = parent.transform.GetChild(i); + Vector3 newPosition = new Vector3(i * spacing, 0, 0); + child.localPosition = newPosition; // Set local position relative to the parent + Debug.Log($"Positioned {child.name} at local position {newPosition} relative to {parentName}"); + } + } + else + { + Debug.LogError($"Parent GameObject {parentName} is null!"); + } + } + + void OnDrawGizmos() + { + // Draw gizmos for debugging purposes + Gizmos.color = Color.red; + DrawGizmoForObject(player1, player1Position); + + Gizmos.color = Color.blue; + DrawGizmoForObject(player2, player2Position); + + Gizmos.color = Color.green; + DrawGizmoForObject(closeCard1, closeCard1Position); + + Gizmos.color = Color.yellow; + DrawGizmoForObject(closeCard2, closeCard2Position); + } + + void DrawGizmoForObject(GameObject obj, Vector3 position) + { + if (obj != null) + { + Gizmos.DrawWireSphere(position, 0.5f); + } + } +} + + + + + + + + diff --git a/Assets/Scripts/CardPositionManager.cs.meta b/Assets/Scripts/CardPositionManager.cs.meta new file mode 100644 index 0000000..ef192b1 --- /dev/null +++ b/Assets/Scripts/CardPositionManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 17903f373ba904c4f9ce5b2d6771a3dc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/MyFaceDownCards.cs b/Assets/Scripts/MyFaceDownCards.cs index fb8d9af..c7ff2bf 100644 --- a/Assets/Scripts/MyFaceDownCards.cs +++ b/Assets/Scripts/MyFaceDownCards.cs @@ -1,14 +1,27 @@ -using System.Collections; using System.Collections.Generic; using UnityEngine; public class MyFaceDownCards : MonoBehaviour { public List myCards; + public float cardSpacing = 2.0f; // Adjust this value as needed + public void TakeCard(Card card) { card.CardDisplay.ChangeToBack(); myCards.Add(card); card.transform.parent = transform; + PositionCards(); + } + + private void PositionCards() + { + for (int i = 0; i < myCards.Count; i++) + { + Vector3 cardPosition = new Vector3(i * cardSpacing, 0, 0); + myCards[i].transform.localPosition = cardPosition; + Debug.Log($"FaceDown Card {myCards[i].name} positioned at {cardPosition} locally within {name}"); + } } } + diff --git a/Assets/Scripts/MyPlayer.cs b/Assets/Scripts/MyPlayer.cs index 51db651..d8421e8 100644 --- a/Assets/Scripts/MyPlayer.cs +++ b/Assets/Scripts/MyPlayer.cs @@ -1,13 +1,26 @@ -using System.Collections; using System.Collections.Generic; using UnityEngine; public class MyPlayer : MonoBehaviour { public List myCards; + public float cardSpacing = 2.0f; // Adjust this value as needed + public void TakeCard(Card card) { myCards.Add(card); card.transform.parent = transform; + PositionCards(); + } + + private void PositionCards() + { + for (int i = 0; i < myCards.Count; i++) + { + Vector3 cardPosition = new Vector3(i * cardSpacing, 0, 0); + myCards[i].transform.localPosition = cardPosition; + Debug.Log($"Card {myCards[i].name} positioned at {cardPosition} locally within {name}"); + } } } +