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 d112570 · Sep 03, 2013 at 03:04 PM · parentchildclonecamera.main

Clone wants a Parent (c#)?

How would you go about moving a clone to the main camera parent. Or should I say how would you turn the new clone into a child of the new Parent (Main Camera). It's a c# script.

// Start Cloning Planets to create the "visit Planet Buttons" for the Main Camera.

if (GameObject.Find(SystemSizeSetup[i].name + "Sphere")){

var clone = Instantiate(GameObject.Find(SystemSizeSetup[i].name + "Sphere")); // Clone Planets

clone.name = "c" + SystemSizeSetup[i].name; // Rename Clones

} // End Cloning

The clones will line up from top to bottom, then you will be able to choose which planet to visit next. This way no matter where you go with the camera, the planets will always be lined up with the camera.

Thx, David.

P.S. is "var" not a java command, why is it working in c#? What would be the c# version?

Comment
Add comment · Show 2
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 ArkaneX · Sep 03, 2013 at 03:31 PM 0
Share

var is a C# keyword as well. It denotes any type, but variable declared using var must be initialized immediately and is strongly typed. For example, you can't do:

 var number;
 number = 1;

but ins$$anonymous$$d you have to use:

 var number = 1;

This declares number variable which is of int type. But if you do:

 var number = "123";

then number will be string.

avatar image d112570 · Sep 03, 2013 at 03:59 PM 0
Share

Neat, this will help a lot, I usually ignored any var data which I though was Java, since I was concentrating on learning c# only and which is faster then Java. So many languages out there, first I learned Basic, then Lingo, now c# and english :-)

1 Reply

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

Answer by MissingSemicolon · Sep 03, 2013 at 03:34 PM

Something along the lines of:

 clone.transform.parent = Camera.main.transform;


That should parent your new clone to the main camera in the scene (whichever camera has been tagged "MainCamera")

Comment
Add comment · Show 5 · 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 d112570 · Sep 03, 2013 at 03:55 PM 0
Share

Thanks a lot, That looks easy enough, but I get an error message saying that is does not contain a definition for transform. I copied and pasted into the script after clone.name. I also tried "clone.transform.parent = myCamera.transform" since I have the transform defined for myCamera, it didn't work either. I the script I have "public Transform myCamera;" in which my $$anonymous$$ain Camera is connected. What am I missing?

avatar image MissingSemicolon · Sep 03, 2013 at 04:00 PM 0
Share

Replace the var with GameObject, so it will look something like this:

 GameObject clone = Instantiate(GameObject.Find(SystemSizeSetup[i].name + "Sphere")) as GameObject; // Clone Planets

I haven't tested this but it should be along the right lines.

avatar image fafase · Sep 03, 2013 at 04:00 PM 0
Share

myCamera is already a transform so :

  clone.transform.parent = myCamera;

should do

avatar image d112570 · Sep 03, 2013 at 04:14 PM 0
Share

clone.transform.parent = myCamera; // This didn't work, but still like to know why it didn't. $$anonymous$$eeps saying there is no transform set.

But this line solved it all GameObject clone = Instantiate(GameObject.Find(SystemSizeSetup[i].name + "Sphere")) as GameObject; // Clone Planets Thanks a lot How does the moving part work anyways, does it first create a clone, then renames it, and then move the renamed clone to the camera, or does it get done all at once till the first loop is complete, then returns to the beginning of the loop until its done with its routine.

avatar image fafase · Sep 03, 2013 at 04:22 PM 0
Share

The reason is probably that you were created an object of type Object which is what Instantiate returns. Then Object does not have a Transform. Doing the as GameObject cast the object into GameObject which now has a Transform. That is what I think.

This is the danger of using UnityScript vs C#. C# would not have allowed you to do that because the reference would have been a GameObject.

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

18 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make a simple tree 1 Answer

How can I make a game object follow an instantiated game object? 1 Answer

[SOLVED] How to make to clone an object and make it parent of the transform? 1 Answer

Instantiate a game object in array then change parent 1 Answer

Calling a function of another object's 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