Should I add the information in both side - unity3d

I am new to unity ,plz forgive me asking these questions
It bumps out : default reference will only be applied in edit mode
Is it important, what is that?
Should I need to add the information(food and border ) to both sides?

The second image are default references. If you set them they are automatically applied after adding this script to an object.
They are not required. And only apply to a script added via the Editor (not by script!). What matters later on runtime are only the values on the GameObject.
Further you can only reference assets from the Assets folder here. They make sense e.g. if you have a button script that uses a certain Click sound, a texture and e.g. a prefab. For these three you now could already define default values so someone using your component doesn't have to assign everything everytime but already has the default references as a kind of fallback.
So in your case it would only make sense, if the borders are prefabs from the Assets that are spawned by this script. The FoodPrefab is even called like this and makes sense to have as a default reference so you don't have to drag it into each and every instance of SpawnFood you create.
And btw just by looking at your settings you should probably directly make your fields of type RectTransform so you can't accidentally reference another object there.

Related

Defining custom state list

When I attach Interactable component to my prefab, I can choose one (or more) of 4 state blueprints, such as DefaultInteractableStates.asset. Although it contains 4 defined states, I would need to remove "Default state" from that. Is there a way I could define my own list of states? I can see the - button to remove state, but the asset is read-only, so I cannot edit it.
This looks like MRTK
=> in general all the original profile assets are read-only protected.
You always need to make a copy/clone of whatever profile you want to change and edit the copy instead and assign the copy to your profiles.
Also see How to configure Interactable.

Unity Visual Scripting Variable

I have a scene that has 3 buttons, one for each level. I made buttons 2 and 3 uninteractable and I want to make it so when you win the 1st you can start the 2nd etc... So I have unchecked the interactable box from the options of button2. Then I went to the script of my player and I have connected the following parts so when he completes the 1st level the button 2 gets to be interactible. But there seems to be an issue.
(This answer only applies if you were loading new scenes.)
Perhaps, the problem is that you can’t save a variable telling which levels are allowed. (Unless you do it through, an actual save mechanic.) this is because unity destroys all objects in a scene when loading a new scene. This removes all data stored in variables. You could get around this from using
DontDestroyOnLoad(gameObject);
this saves the gameObect variable you put in the parentheses through scene loading. You can attach a script that would store the variables to this, to save information.
If you can’t figure out how to get the variables from other scripts, use this:
var newVariable = GameObjectVariable.GetComponent<scriptName>().variableName;
I see you were using visual coding, so if you can try and figure out how to find these methods in there, it should work.
If you want to use actual save mechanics, go to this link:
https://docs.unity3d.com/ScriptReference/PlayerPrefs.html/
Set Variable need to receive a flow input.

Why shaders doesn't includes to build?

I am new in Unity and there is something looks weird to me. I created a UnlitTextureYUV.shader file then I use it in my script like this
...
meshRenderer.material = new Material(Shader.Find("UnlitTextureYUV"));
...
Then in editor I click on run button and I see that everything is working properly, ok. Then I click File->Build&Run and I get an error ArgumentNullException that means shader not found.
I tried to find out what is going on and found such answer on Unity community
https://answers.unity.com/questions/1147277/textures-from-local-works-in-editor-missing-in-bui.html
As far as I understand in order to use shaders in build dynamically I need to create dummy material add texture to it and even create dummy object (disabled) and add this material to this object. In this order my shader will be included in build and I will be able to find it dynamically in code by invoke this method Shader.Find("UnlitTextureYUV").
Question is - is there more straight way to include shader in build? Why I need to create dummy objects in order to include this file in build? Or I miss something?
You have to add all your shaders to Unity's 'Always included shaders' list in the
graphic settings.

Filtering an object field in Unity Editor Extension

I'm looking to use Unity's ObjectField to have users search for objects of a particular type. I know the constructor allows for a typeOf(objectType), but that does not seem to allow for filtering on custom components.
Essentially, a previous editor script I have sets up objects, and places a unique custom script on each of the components, but I've been unsuccessful in utilizing the ObjectField to search for just those objects. If I change the typeOf in my object field to be my component, it is always empty, despite there being many prefabs with that script attached in my project.
Has anyone had any success with this? Using GameObject finds them, but this finds all game objects. Is there any way to restrict this? Or to keep it only looking at particular folders?
Adding a filter while the field itself stays as type Object is a bit tricky. Here's one way.
Use ShowObjectPicker
Try opening a custom ObjectPicker. To do so you'll have to hide the default object picker and call one with a set searchFilter. It is quite a bit of work.
Setting searchFilter
Use https://docs.unity3d.com/ScriptReference/EditorGUIUtility.ShowObjectPicker.html with a searchFilter that matches the component you add to every object you want to show up in an ObjectPicker. for example "t:objectType".
There's some good information on using ShowObjectPicker at https://answers.unity.com/questions/554012/how-do-i-use-editorguiutilityshowobjectpicker-c.html
Hide default object picker
Here's a post with a way to hide the default object picker Is there any way to hide the "Object picker" of an EditorGUILayout.ObjectField in Unity Isnpector?
Show picker
You'll need to create your own Editor GUI.Button to bring up the ShowObjectPicker with the custom searchFilter.
Assets searchFilter
As a sidenote, to do the same with file assets use a "l:labelName" fileFilter instead of "t:objectType". You can set the label with the Unity Editor UI as shown here:
or with "ref:relative/path/from/assets/to/material/material.mat"

Unity3D Editor - Creating Automatically Unique-Named Game Objects?

I have some Unity editor integration scripts with that the user should be able to create game objects in the opened scene and I'd like to be able to automatically give each newly created object a unique, preferably sequentially numbered name, e.g.
Actor001
Actor002
Actor003
...
Actor100
etc.
So I was wondering if there are any useful methods known already or whether I have to implement this behavior myself completely, in which case I'm wondering how to figure out the sequence numbering from already existing objects. Any Ideas?
Found it:
GameObjectUtility.GetUniqueNameForSibling(parent, name);