Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions Assets/Scripts/CardPositionManager.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}








11 changes: 11 additions & 0 deletions Assets/Scripts/CardPositionManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion Assets/Scripts/MyFaceDownCards.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MyFaceDownCards : MonoBehaviour
{
public List<Card> 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}");
}
}
}

15 changes: 14 additions & 1 deletion Assets/Scripts/MyPlayer.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MyPlayer : MonoBehaviour
{
public List<Card> 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}");
}
}
}