Best Way to Set Up Game with Multiple Characters and 1000s of objects

Hi there. I am making a dollhouse game. There isn’t a winner or loser, it is just for little kids to play dollhouse with. I will have lots of characters for them to play with. They will be able to drag and drop them wherever they want. The child will also be able to drag and drop items on each character. I would then want the character to be able to walk around with these items. I want the object(s) to be parented to the character until the character drops the item. The character won’t have a rigidbody because it will just be a flat sticker like image that can be moved - like Colorforms (if you remember what those are). I already have each character set up to drag and drop wherever. I placed a circle collider 2d on each hand. I want the child to be able to drag an item into the hand of whichever character they choose. That item should then stay in that hand until the child drags that item out of the hand. It should move around with the character.

Thank you in advance for any support, advice, or code.
Rachel

If this question wasn’t specific enough…maybe if someone could help me with the C# code for parenting one object to another. I’d probably be able to go from there. Thank you!

oneObject.transform.parent = another.transform;

Good luck with your project!

  • Joe
2 Likes

Thank you Joe!!! I attached it to a vase to test it … here is the code …

using UnityEngine;
using System.Collections;

public class PickupObject : MonoBehaviour {

    //we also want to know what the player is by accessing the BabyManager.cs script
    private BabyManager baby;

    // Use this for initialization
    void Start () {
        //find objects of type BabyManager - so find babies in the scene
        baby = FindObjectOfType<BabyManager>();

    }

    void OnCollisionEnter (Collision other) {
        if (baby != null){

            baby.transform.parent = other.transform;
           

        }
    }
}

and it didn’t work. Can you tell what I did wrong? I attached a screenshot for both the baby and the vase to show you how I have it setup. I appreciate you taking a look. :wink:

THANK YOU!!!


OK, I got it to work if I do this…

void OnTriggerEnter2D (Collider2D other) {
if(other.gameObject.name == “Vase-Yellow”){
other.transform.parent = GameObject.Find(“RightHand”).transform;
}
}

However, it works whenever I collide with anything…I want it to work if I drag and drop an item on top of a character…only if it is dropped on the character. Any ideas? Thanks!!!

Lmao. I only read the thread title and then immediately after, your reply.

Hmm, I’m not sure. You’re already checking other.gameObject.name, which seems like the right track to me. Think carefully about which object this script is on, and what the other object should be, and I bet you’ll get it. (If you’re like me, you’ll probably wake up with the answer in the morning!)

Failing that, you may have to just experiment — try the script on different objects, check for different names, until something clicks for you.

Thank you for your help Joe. :slight_smile: I did something like this and it works okay for now…

//void OnCollisionEnter(Collision other){
    void OnTriggerEnter2D (Collider2D other) {
        if(other.gameObject.tag == "Pickable"){
            Debug.Log ("Vase-Yellow");
            other.transform.position = GameObject.Find("RightHand").transform.position;
            other.transform.parent = GameObject.Find("RightHand").transform;

            //other.rigidbody.isKinematic = true;   
        }
    }

    //void OnCollisionEnter(Collision other){
    void OnTriggerExit2D (Collider2D other) {
        if(other.gameObject.tag == "Pickable"){
            other.transform.parent = null;
           
            //other.rigidbody.isKinematic = true;   
        }
    }

Thank you for your help.
Rachel

1 Like