Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Msurdej · Nov 26, 2012 at 10:45 PM · c#parentpick-up

A growing problem. the children keep getting bigger.

I'm working on a Unity game where the player must pick up objects that then follow him. These objects are parented to the player before it makes a new instantiation of the object. However, this causes the new object that is spawned to be larger in size. Here is my code:

 using UnityEngine;
 using System.Collections;
 
 public class Pickery : MonoBehaviour
 {
     public int Counter = 100;
     public GameObject parson;
     public int Timekeeper = 10;
     public int Collection = 0;
     public GameObject cameran;
     
      void OnTriggerEnter (Collider other)
     {
         Debug.Log ("Counter:" + Counter);
         cameran.SendMessage("Plus", Timekeeper);
         cameran.SendMessage("Wumbo",Counter);
         parson.transform.parent = transform;
         Collection++;
         parson.transform.localPosition = new Vector3(0, 0, -Collection);
         parson = Instantiate(parson, new Vector3(Random.Range(10,-35),921,Random.Range(267,310)), Quaternion.identity)as GameObject;
     }
 }


I believe the cause of this problem is when it is picked up by the parent. removing the two lines that parent the object to the player causes the objects not to grow, but doesn't put them behind the player(puts them at 0,0, - something). Is there a way I can have it ignore the parent's size when it instantiates a new object, or have it place the objects behind the player and following the player with the parenting lines removed?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by coastwise · Nov 29, 2012 at 04:47 PM

The trouble is that when you apply the parent, the child will change its scale to stay the same size. For example, the player is scaled by 0.9, the other object is 1. I make the player the parent, the child changes its scale to 1.11 so that it looks the same. (0.9 * 0.111 = 1)

I can see to straightforward ways to solve this: instantiate the new object before parenting the old one to the player, or have a reference to a prefab that you instantiate instead of copying one that already exists in game (this will also avoid (Clone) (Clone) (Clone)).

Here is my take on the first proposed solution to the code you posted above:

 using UnityEngine;
 using System.Collections;
 
 public class Pickery : MonoBehaviour {
     public int Counter = 100;
     public GameObject parson;
     public int Timekeeper = 10;
     public int Collection = 0;
     public GameObject cameran;
 
     void OnTriggerEnter (Collider other) {
        Debug.Log ("Counter:" + Counter);
        cameran.SendMessage("Plus", Timekeeper);
        cameran.SendMessage("Wumbo",Counter);
        Collection++;
        parson.transform.localPosition = new Vector3(0, 0, -Collection);
        GameObject newparson = Instantiate(parson, new Vector3(Random.Range(10,-35),921,Random.Range(267,310)), Quaternion.identity)as GameObject;
        parson.transform.parent = transform;
        parson = newparson;
     }
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Msurdej · Dec 01, 2012 at 07:29 PM 0
Share

Got that to work after putting the line where it re-locates the object after where it parents the object.

Like so:

GameObject newparson = Instantiate(parson, new Vector3(Random.Range(10,-35),921,Random.Range(267,310)), Quaternion.identity)as GameObject; parson.transform.parent = transform; parson.transform.localPosition = new Vector3(0, 0, -Collection); parson = newparson;

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

GetComponentInChildren with tag in two variable 3 Answers

Moving a GameObject reffering to the coordinates of the parent Object 1 Answer

How to calculate required rotation of a parent object by a given rotation of a child 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges