• 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 Powarader · Aug 19, 2015 at 09:42 PM · parent-child

How to set parent

Hey all! I'm making this game where you have a certain number of "hexapes", but I can never know how much there are, because the hexapes are procedurally generated. An hexape is simply a center circle (smaller then the other ones) and six bigger circles disposed like a hexagon. Every one of those seven circles have the same parent : an empty gameobject called hexape. The hexapes appear in the level with a distance that makes two of the circles of two different hexapes to overlap. Hope you're getting it so far. What I want to do is when an hexape is rotated (each time you click or tap it rotates exactly 60 degrees), the common circles between the two hexapes become child of the rotating one, and the one that's not rotating has those two circles set to null, so they should disappear until the rotating hexape brings back two circles.

If you're not understanding because my english is bad or because I didn't explain as I should, please post a comment, I'll try to explain better.

Here's what I have so far:

(this script is attached to all the circles in the scene (except for the center))

 using UnityEngine;
 using System.Collections;
 
 public class CircleDestroyer : MonoBehaviour {
 
     void OnTriggerEnter2D (Collider2D any) {
 
         if (any.gameObject.GetComponent<HexapeConstructor>().isRotatingMessage() == true) {
         
             any.gameObject.transform.SetParent(this.gameObject.transform.parent);
             this.gameObject.GetComponent<SpriteRenderer>().sprite = null;
         
         }
     }
     
 }


Something weird is happening : when the hexapes rotate simultaneously, the last one that got clicked gets smaller and rotates with the other hexape, like the whole hexape is child of the other one. That's not what I want.

Btw, yes, all circles have a trigger circle collider.

Hope you can help me!

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

Answer by Youri1er · Aug 20, 2015 at 07:44 AM

Sorry i'm not sure to understand what you want.

Replace that: any.gameObject.transform.SetParent(this.gameObject.transform.parent);

By : any.gameObject.transform.parent = this.gameObject.transform.parent;

Comment
Add comment · Show 2 · 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 Powarader · Aug 20, 2015 at 12:19 PM 0
Share

Hey, yeah, I tried that already, what happens is that the circle does become child of the other hexape, but it stays in the same position, it doesn't rotate around the center...

What don't you understand? Should I post pics?

avatar image Youri1er · Aug 20, 2015 at 01:51 PM 0
Share

Ok i see what you need.

You must see how to rotate around a point.

https://www.youtube.com/watch?v=FqiGuTtjm$$anonymous$$g

newX = centerX + (point2x-centerX)$$anonymous$$ath.cos(x) - (point2y-centerY)$$anonymous$$ath.sin(x);

newY = centerY + (point2x-centerX)$$anonymous$$ath.sin(x) + (point2y-centerY)$$anonymous$$ath.cos(x);

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Displayed parent position moves with child? 1 Answer

Raycast Layermask doesn't ignore no layered Parent? 1 Answer

Intantiated objects being created but being invisible...[PICTURES] 1 Answer

Jittery world around stationary character 1 Answer

How to create a child object of an object with a specific tag? 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