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 odival · Dec 31, 2014 at 07:11 PM · gameobjectchildchildrenenableinstantiated

How to enable children of child game object?

I'm following Quill18's Multiplayer FPS Tutorial and in Part 5 we have to enable some components in a instantiated player prefab. However, in my particular case, the player itself is a child of another GO (caller Player GO) and there's two cameras (Camera1 set to depth only and Camera 2 set to skybox) that are children of the child.

I cant enable the 2 cameras gameobjects no matter what I try. Help?

There below is my hierarchy for the player GO...

alt text

and the script that instantiates players:

 using UnityEngine;
 using System.Collections;
 
 public class NetworkManager : MonoBehaviour {
 
     public GameObject standbyCamera;
     private GameObject player;
     private GameObject camera1;
     SpawnSpot [] spawnSpots;
 
     // Use this for initialization
     void Start () {
         spawnSpots = GameObject.FindObjectsOfType<SpawnSpot> ();
         Connect ();
     }
 
     void Connect () {
         PhotonNetwork.offlineMode = false;
         PhotonNetwork.ConnectUsingSettings ("RPGVR 1.0.0");
         }
 
     void OnGUI (){
         GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString() );
         }
 
     void OnJoinedLobby() {
         PhotonNetwork.JoinRandomRoom ();
         }
 
     void OnPhotonRandomJoinFailed() {
         PhotonNetwork.CreateRoom (null);
         }
 
     void OnJoinedRoom(){
         Debug.Log ("OnJoinedLobby");
 
         SpawnMyPlayer ();
         }
 
     void SpawnMyPlayer (){
         if (spawnSpots == null) {
             Debug.LogError ("No Spawn Spots avaiables. Don't Panic");
             return;
         }
         SpawnSpot mySpawnSpot = spawnSpots[ Random.Range (0, spawnSpots.Length) ];
         GameObject myPlayerGO = (GameObject) PhotonNetwork.Instantiate("Player GO", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
         //Disable the Standby Camera
         standbyCamera.SetActive(false);
         //Enable "Sky Dome" Child of "PlayerGO" Game Object
         myPlayerGO.transform.FindChild("Sky Dome").gameObject.SetActive(true);
         //Enable Components in "Player" Children of "PlayerGO" Game Object
 
 //The camera code below does not work =(
 
         camera1 = GameObject.FindWithTag("MainCamera");
         camera1.SetActive(true);

 //Below code is okay

         try
         {
             player = GameObject.FindWithTag("Player");
 
             player.GetComponent<MouseLook>().enabled = true;
             
             MouseLook mouseScript = myPlayerGO.GetComponentInChildren<MouseLook>();
             if(mouseScript != null)
             {
                 mouseScript.enabled = true;
             }
             CharacterMotor motorScript = myPlayerGO.GetComponentInChildren<CharacterMotor>();
             if(motorScript != null)
             {
                 motorScript.enabled = true;
             }
             
             FPSInputController controlScript = myPlayerGO.GetComponentInChildren<FPSInputController>();
             if(controlScript != null)
             {
                 controlScript.enabled = true;
             }
 
         }
         catch
         {
             Debug.Log ("Error finding children");
         }

     }
 }
 

playerhierarchy.jpg (4.9 kB)
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 ramp · Jan 01, 2015 at 09:24 AM

Hello,

First of all you have to Make children variable as private to public and assign from Hierarchy.

  public GameObject player;
  public GameObject camera1; 
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 odival · Jan 01, 2015 at 06:46 PM 0
Share

Sorry but can you explain a little more? I made the children var public and assigned from hierarchy, however the player must be instantiated into the scene so, even if I assigned the game objects correctly, they vanish as soon as I delete the player from the scene (because he's suposed to be a prefab instantiated at runtime).

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Grabbing all Children and components of those children 1 Answer

enable/disable child objects? 2 Answers

C# Find component InChildren 3 Answers

How to check parent value instead name value(more details in post) 3 Answers

Target child of child without knowing name? 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