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 Itinerant · Sep 06, 2012 at 05:23 PM · c#camerainstantiatephoton

Activating a child object in C#

Complete newbie with C#, but I'm trying to use Photon Cloud and this is looking like the only way to go. My problem is this: I can't find a way to activate the camera on an instantiated first person controller. I get an "error CS0246: The type or namespace name 'MainCamera' could not be found. Are you missing a using directive or assembly reference?"

My code: void OnJoinedRoom(){

         GameObject Avat = PhotonNetwork.Instantiate ("myFPC", new Vector3(0,2,0), Quaternion.identity, 0);
 
         MainCamera currentCam = Avat.Find("Main Camera");
         currentCam.active = true;
         
     }
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
1
Best Answer

Answer by kmeboe · Sep 06, 2012 at 06:19 PM

I'm not familiar with Photon Cloud, but I'm guessing "Main Camera" is an object in your scene? In that case, it's probably just a "GameObject". Try this:

 void OnJoinedRoom(){
 
            GameObject Avat = PhotonNetwork.Instantiate ("myFPC", new Vector3(0,2,0), Quaternion.identity, 0);
     
            Transform currentCam = Avat.transform.Find("Main Camera");
            currentCam.active = true;
     
 }

For more information about accessing objects from other objects in Unity, see here: http://docs.unity3d.com/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html

Comment
Add comment · Show 4 · 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 Itinerant · Sep 06, 2012 at 06:24 PM 0
Share

That does something at least :) Unfortunately, now I have a new error message:

"Static member 'UnityEngine.GameObject.Find(string)' cannot be accessed with an instance reference, qualify it with a type name ins$$anonymous$$d"

Any ideas on this one? And thank you for helping!

avatar image kmeboe · Sep 06, 2012 at 06:36 PM 0
Share

You're welcome; hopefully we'll get you there. :)

Try "Avat.transform.Find" ins$$anonymous$$d. I've updated the above code to match.

avatar image Itinerant · Sep 06, 2012 at 06:52 PM 0
Share

That didn't quite fix it, but it did give me enough information that I could :D Swapped the code to this:

Transform currentCam = Avat.transform.Find("$$anonymous$$ain Camera")

Then it worked :) Now on to the next problem. Thanks a bunch!

Oh, and can you update your code with that in case anyone else shows up to look at this?

avatar image kmeboe · Sep 06, 2012 at 07:51 PM 0
Share

Ah, good find. Sure, I'll update.

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

8 People are following this question.

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

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Spawn Ground right next to current ground 1 Answer

C# 2d Instantiate GUIText and lock it to position on map, not to follow camera. 1 Answer

How do I stop Script from making multiple Cameras? 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