Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Disabling parent GameObjects form another scene

Discussion in 'Scripting' started by nelfoxix, Nov 7, 2019.

  1. nelfoxix

    nelfoxix

    Joined:
    Feb 3, 2019
    Posts:
    2
    So i have my racing game and a want to select the car by having multiple bodies on the Player GameObject and the buttons in the menu would disable o body and enable the other one. And what im trying to do is put the script in the Canvas containing the car select buttons then in that script referencing to a GameObject that will be a body of the car, but when in the Unity editor i try to put the body in the reference slot it doesn't want to go in there. Any help?
     
  2. Neriad

    Neriad

    Joined:
    Feb 12, 2016
    Posts:
    125
    Not sure I understand what you are saying but :
    - Double check that the property field has the right type. You cannot put an Image into a Text field for example.
    - If the object is a prefab and the other object is inside the scene, you cannot associate them together.
     
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You can't reference something in one scene in another scene via the inspector. You can establish references between objects in different scenes at runtime instead. After loading both scenes in game I typically just have one object find the other using a unique tag.
     
    Last edited: Nov 7, 2019
  4. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    746
  5. nelfoxix

    nelfoxix

    Joined:
    Feb 3, 2019
    Posts:
    2
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Activator : MonoBehaviour
    6. {
    7.  
    8.         public int Targeter;
    9.  
    10.     GuidReference.gameObject;
    11.         public void CarSelectOne()
    12.     {
    13.  
    14.     }
    15.      
    16. }
    Ok, but i can't seem to understand how to add a GUID Refernece field. Do you know how to do that? Oh yeah and i alredy have the file needed in my Assets folder.
     
  6. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    746
    To Use:

    Add a GuidComponent to any object you want to be able to reference.

    In any code that needs to be able to reference objects by GUID, add a GuidReference field.

    GuidReference.gameObject will then return the GameObject if it is loaded, otherwise null.

    Look in the CrossSceneReference/SampleContent folder for example usage.

    Load up the LoadFirst scene, and then use the SceneLoader object to load 'LoadSecond'

    You should see the CrossSceneReferencer object find the CrossSceneTarget object, and set both of them to start spinning.
     
    Meceka likes this.