Please Help. I just can’t figure this one out and I want to cry like a little girl. ![]()
So I am able to put the costume on the players
Here is a pic of before I put the costumes on…

here is the players with the costumes on…

I can move the players around with the costumes…it works like a charm. However, if I take the costume of the player and place it on the ground, then move the player around, the costume moves around with the player (because it is still a child of the player). Here is a pic to illustrate what I mean…

Here are the settings of the player’s head (which I have put the code on - the code C# file is shirt.cs)
And here is settings on each of the costumes
Here is the code:
Here is Shirt.cs
using UnityEngine;
using System.Collections;
public class Shirt : MonoBehaviour {
//ON BABY
//CHARACTER PICKING UP ITEM
void OnTriggerEnter2D(Collider2D other) {
if (other.gameObject.name.Contains("Shirt")) {
if(DragClothes.isChilded == false){
//change position of the object to the character's right hand
other.transform.position = this.transform.position;
//parent the object to the child's right hand
other.transform.parent = this.transform;
this.transform.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
}
}
}
//DROPPING ITEM
void OnTriggerExit2D (Collider2D other) {
if(other.gameObject.name.Contains("Shirt")){
if(DragClothes.isChilded == true){
other.transform.parent = null;
//make it so that the object is NOT parented to the character any more
DragClothes.isChilded = false;
}
}
}
}
Here is the code for DragClothes.cs
using UnityEngine;
using System.Collections;
public class DragClothes : MonoBehaviour {
public Renderer rend;
int originalSortOrder = 0;
bool blueNoContact = true;
public static bool isChalk = false;
public ItemTracker itemTracker;
public DirectionRaycasting2DCollider directionCollider;
Vector3 origScale;
public Transform Doll;
public static bool isChilded;
//Drag and Drop Method
void Start(){
//original scale of object
origScale = transform.localScale;
originalSortOrder = gameObject.GetComponent<Renderer> ().sortingOrder;
itemTracker = FindObjectOfType <ItemTracker>();
directionCollider = FindObjectOfType <DirectionRaycasting2DCollider>();
//set isChildred to default false
isChilded = false;
}
//<<----------------------------------------------------------------------------------//
//IF DRAGGING DOLL YOU DON'T WANT CLOTHES TO FALL OFF WHEN INTERACTING WITH OTHER DOLLS
void OnTriggerEnter2D(Collider2D other) {
if(gameObject.transform.IsChildOf(Doll)){
//now it is child of Doll
isChilded = true;
}
}
void OnTriggerExit2D(Collider2D other) {
if (gameObject.transform.IsChildOf (Doll)) {
//now it is NOT child of Doll
isChilded = false;
}
}
//<<----------------------------------------------------------------------------------//
//SHRINK ITEMS THAT GO INTO CHEST
/*
void OnTriggerEnter2D(Collider2D other) {
if ((other.gameObject.tag == "Cabinet") && (!(gameObject.transform.IsChildOf(Doll)))) {
transform.localScale = new Vector3((0.5f * origScale.x),(0.5f * origScale.y),(0.5f * origScale.z));
}
}
void OnTriggerExit2D(Collider2D other) {
if ((other.gameObject.tag == "Cabinet") && (!(gameObject.transform.IsChildOf(Doll)))) {
//return to orginal size
transform.localScale = new Vector3( origScale.x,origScale.y,origScale.z);
}
}
//END SHRINK
*/
void OnMouseDrag()
{
Vector3 point = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition.y,(transform.position.z-Camera.main.transform.position.z)));
point.z = transform.position.z;
transform.position = point;
//position the object a bit higher so that it is above other items when picking up
gameObject.GetComponent<SpriteRenderer> ().sortingOrder = 250;
gameObject.GetComponent<Renderer> ().sortingLayerName = "Toppest";
}
void OnMouseUp(){
directionCollider.checkOutOfCabinet (gameObject);
//if gameObject is no longer in box then return
if (itemTracker.itemsInBox.Contains (gameObject)) {
return;
} else { //else if gameobject is still in box then ...
//first make sure not one of the following...if so set sorting layer to default
if ((gameObject.name.Contains("Shirt")) || (gameObject.name.Contains("Hat")) || (gameObject.name == "Bowl") || (gameObject.name == "Bowl2") || (gameObject.name == "Bowl3") || (gameObject.name == "Bowl4") || (gameObject.name == "Plate") || (gameObject.name == "Plate2") || (gameObject.name == "Plate3") || (gameObject.name == "Plate4") || (gameObject.name == "Cup") || (gameObject.name == "Cup2") || (gameObject.name == "Cup3") || (gameObject.name == "Cup4")){
gameObject.GetComponent<Renderer> ().sortingLayerName = "Default";
} else {
//Change sorting order of that item so that it is above stuff
gameObject.GetComponent<Renderer> ().sortingOrder = 200;
gameObject.GetComponent<Renderer> ().sortingLayerName = "Top";
}
}
}
}
Please take a look if you could…and let me know where I am failing!!! I so appreciate it!!!
Thanks…Rachel

