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?
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.
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.
This makes cross-scene referencing easy.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Activator : MonoBehaviour
{
public int Targeter;
GuidReference.gameObject;
public void CarSelectOne()
{
}
}
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.
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.