Why shaders doesn't includes to build? - unity3d

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.

Related

Unity 3D First Person Controller Script Reference

The FPS Controller Script can be found in Unity Standard Assets folder under Characters/FirstPersonCharacters. I added it to an object called Player. And when I want to pause the game (I've done a pause menu UI), I don't like that it still follows the mouse on the screen, so I want to freeze that rotation. Since I use the free rigidbody version, the RigidbodyConstrains does not work. I need to get a reference to that script to write .enabled = false; But it does not work, the Unity does not recognize it. I wrote:
GameObject.FindGameObjectWithTag("Player").GetComponent<FirstPersonController>().enabled = false;
But it does not work, even if I import UnityStandardAssets(I mean in the script: using UnityStandardAssets;)
I've tried a lot of other solutions, but I can't find the right one! Could you please help me? Thanks in advance!
vs2019error_image
inspector view
i have tested in my visualstudio 2017 i have to add that line:
using UnityStandardAssets.Characters.FirstPerson;
so i have taken the script directly from folder standard Asset
if you see into the script you have this line:
namespace UnityStandardAssets.Characters.FirstPerson
you have to precise the path where to find the class
this line is proposed by VisualStudio 2017, dunno why not by visual studio 2019
For anyone else in the future coming across this, the current firstpersoncontroller script only requires that you add
using StarterAssets;
and then you can use GetComponent()

Should I add the information in both side

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.

How to add the new unity uxml(via ui builder) to game screen?

I installed the new Unity UI Builder. Everything works just fine...
But how do I add the uxml to my scene or how do I attache it to camera?
I tried to drag and drop the uxml to camera and I searched for a component, but I couldn't find anything... Is there any official documentation?
You must use an gameObject with PanelRenderer.cs attached to it:
For now, I only know you have to set UXML file and USS file. In play mode, by magic (I still don't understand how unity does it), it will render.
In the Github project you can see how things are for now. UIElementsUniteCPH2019RuntimeDemo
EDIT:
The project linked above uses UI Builder 0.8.
Runtime support is still not available using the packet manager.
You can add the preview version to your project by adding the following line to your manifest.json (it's located in the projects Packages-folder)
"com.unity.ui.runtime": "0.0.4-preview"
You may want to check whether a newer version is available.
Keep in mind that the preview version is intended for previews only. The api and workflow might change with newer versions.
Once runtime support is enabled you can use the Panel Renderer as described above.
In Unity 2021.2, when you add a UI Document to the hierarchy, a PanelSettings asset is automatically created and assigned to the that UI Document.
Simply add your uxml file to the UI Document -- there is no Panel Renderer component anymore.
Even though the UI Builder offers a preview of the menu over the actual game scene, there is no way to use that menu in a game using Unity's functionality or packages. To do that we need to use the code that comes with the demo by Damian Campeanu from Unite Copenhagen 2019 that you can find here: https://github.com/Unity-Technologies/UIElementsUniteCPH2019RuntimeDemo.
The demo has following structure.
Structure of the project
The files that we are interested in are located in Assets/UIRuntime folder. Simply copy this folder into Assets folder of your project.
After copying the the folder,create empty game object, and add two components in the inspector. Panel Scaler and Panel Renderer.
Game menu object with panel scaler and panel renderer components
Panel Scaller is responsible for scalling your menu for the display. Choose "Constant Physical Size" and 96 for both Reference and Fallback DPI. Those are the values from the original demo and 96 DPI is a typical pixel density for most computer screens (it is different on mobiles and high density screens).
Panel Renderer is the place where you will set your UXML and USS (Unity Style Sheet) files (Uxml and Unity Style Sheet fields. Leave the last two of fields empty, and tick the "Enable Live Updates" checkbox. This will enable you to show the updates in the game viewport as you make them.
I wanted to comment under existing answer by Pablo but I'm new so I can't.

unity3d: how to use OpenFolderPanel

I'm new to unity. I want to try this tutorial but I failed.
I created a GameObject - UI - Button, and tried to add script to Canvas. But I got this error. Any help would be appreciated.
OpenFolderPanel is an Editor script which lets people to make some customized function for Unity Efitor.
If you want to click button to show file dialog in your game, you can try StandaloneFileBrowser
Alright, I know your mistake. When you create a c# script, do as follows (if you want to attach it to a gameobject).
1) Select the gameobject in the heirarchy.
2) Click add component in the inspector window.
3) Type in the name of your new script, and Unity will generate a basic script derived from MonoBehaviour automatically.
BTW, game objects have monobehaviour derived scripts on them (in singleplayer). The script you are using is derived from EditorWindow, not MonoBehaviour. Personally, I have not used a custom editor, but I think the script you are using should work automatically without having to attach it to a gameobject.

using unityscript to write a popup for unity 3d based app for ios

I am trying to write apopup plugin for my unity 3d ios based app, I want to write a plugin that will create a button that will open a new window, and in the new window put a link to a website. I know how to generate a button, but then I get stuck, help any body ?!, thanks.
In case you understand plug-in as a set of GUI elements, you can use the new ModalWindow (v4.1.2) or make your very own custom via the GUI class.
http://docs.unity3d.com/Documentation/Components/GUIScriptingGuide.html
http://docs.unity3d.com/Documentation/ScriptReference/GUI.html
In case you don't like UnityGUI, you can get some other third-party libraries to get your job done, as NGUI: http://www.tasharen.com/?page_id=140
Take a look at Unity's Asset Store for more packages.