Quantcast
Channel: Questions in topic: "parenting"
Viewing all articles
Browse latest Browse all 302

Some Box Collider 2Ds seem to shift on some instances of a prefab

$
0
0
I've been banging my head against the desk for hours. I hope someone can help me with this.

The issue is: Some Box Collider 2Ds aren't clickable, even though those Box Colliders are objects on instances from the same parent prefab.

I'm newish to Unity and C#, but I've tried to be as detailed as possible below. This is my first time posting a question here, so I hope I'm doing it adequately.

First, here's a video showing the issue. As you can see, when I hover over each of the card stats on the card, the yellow triangle sprite appears, as expected. This behavior is consistent for the first two cards in the stack. However, on the third card, only the bottom two card stats operate according to my expectation.

https://youtu.be/vFu0Q2kXrN4

I checked to see if the OnMouseOver() method was even reacting to the first 4 card stats on card three. It isn't. So, for some reason OnMouseOver() stops behaving as expected. This is especially strange considering that the Box Collider 2Ds do appear to be active and in the correct position (according to the Scene view during run-time, see image below)

![alt text][1] I then thought that maybe the z position of the cards themselves are causing a complication, but even when I set all of the z positions to 0, the issue persists.

Also, I tried adjusting the x and y positions of each card, just to search for different behavior, but the issue persists.

The cards are dealt at Start() from a GameManager script attached to the main camera: //player cards behavior Shuffle(playerCards); pxpos = 6f; pypos = -1f; pzpos = 0f; for (int i = 0; i < playerCards.Length; i++) { playerCards[i].tag = "PlayerCard"; Instantiate(playerCards[i], new Vector3(pxpos, pypos, pzpos), Quaternion.identity); pxpos -= 0.5f; pypos += 0.5f; pzpos -= 0.1f; } //computer cards behavior Shuffle(computerCards); cxpos = -6f; cypos = -1f; czpos = 0f; for (int i = 0; i < computerCards.Length; i++) { computerCards[i].tag = "ComputerCard"; Instantiate(computerCards[i], new Vector3(cxpos, cypos, czpos), Quaternion.identity); cxpos += 0.5f; cypos += 0.5f; czpos -= 0.1f; } playerCardScore = playerCards.Length; computerCardScore = computerCards.Length; } The cards themselves are instances of a prefab (see image below). Each card stat is a child under the main card object. Each child has it's own Box Collider 2D that's meant to register the OnMouseOver(). ![alt text][2] Here's the OnMouseOver() code. public void OnMouseOver() { Debug.Log("OnMouseOver is active"); //determines which stat value to select from the player card if (cardBehavior.isFaceUp && cardBehavior.isPlayerTopCard) { spriteRenderer.enabled = true; computerTopCard = cardBehavior.GetComputerTopCard(); switch (gameObject.name) { case "stat0": playerStat = cardBehavior.stat0; computerStat = computerTopCard.GetComponent().stat0; break; case "stat1": playerStat = cardBehavior.stat1; computerStat = computerTopCard.GetComponent().stat1; break; case "stat2": playerStat = cardBehavior.stat2; computerStat = computerTopCard.GetComponent().stat2; break; case "stat3": playerStat = cardBehavior.stat3; computerStat = computerTopCard.GetComponent().stat3; break; case "stat4": playerStat = cardBehavior.stat4; computerStat = computerTopCard.GetComponent().stat4; break; case "stat5": playerStat = cardBehavior.stat5; computerStat = computerTopCard.GetComponent().stat5; break; default: playerStat = 0; break; } //Debug.Log("Player " + gameObject + " of " + playerStat + " vs Computer " + computerTopCard + " of " + computerStat); }

I'm absolutely at a loss. Any help is much appreciated! [1]: /storage/temp/185808-boxcolliders.png [2]: /storage/temp/185805-prefab.png

Viewing all articles
Browse latest Browse all 302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>