• Get the text width in text and truncate the omitted operation in unity


    preface In the ugui of unity, we sometimes have various requirements for the text control, such as the text overflow attribute of CSS in HTML. We want to display a paragraph of text if it is not long enough, truncate it if it is especially long, and add a suffix such as… After it. Well, […]

  • Usage of unity avprovider plug-in


    1. Create a new mediaplayer component 2. Create a new avprovideo component under canvas And assign the mediaplayer component created in the previous step to the mediaplayer on the avprovider component 3. Put the video to be played in the streamingassets folder The next step is to call with code 1、_ mediaPlayer. Openvideofromfile (mediaplayer. Filelocation. […]

  • 2022-03-09 switching between two scenes of unity 3D


    Article catalogue effect Implementation steps 1. Create a scene 2. Add button 3. Write c# script to realize switching 4. Add component to button 5. Add two scenes to build Test effect reference material effect Click the button in Scene1 to enter scene2. Implementation steps 1. Create a scene Right click in assets to create […]

  • [solution] nullreferenceexception: object reference not set to an instance of an object XXXX


    Game engine: unityVersion: 2019.4.6f1 [2017 version or above]Compilation platform: Visual Studio 2019 Problem screenshot Problem description describe Original text [error] nullreferenceexception: object reference not set to an instance of an object XXX Chinese Translation Null reference exception: the object reference is not set to the instance XXXX of the object Solution Check and solve the […]

  • Teach you the production of unity scene switching progress bar


    30 seconds to teach you unity scene switching progress bar First ask a question: why use the progress bar and under what circumstances? 1、 Create game scenes and build panel UI 2、 Add code (1) After loading, enter the complete code of the scene (2) After loading, you need to press the key to enter […]

  • Solve the problems encountered in using fairygui in unity


    first! first! first! First of all, due to historical problems, the UI editor used in the project is not the GUI or ngui used by the public, but the fairygui used by the minority. This UI system is very convenient to use, and it also provides many UI coding cases, which is at least a […]

  • How does unity textasset read configuration files


    1. Supporting file types .txt .html .htm .xml .bytes .json .csv .yaml .fnt 2 find files 1 //Load texture from disk TextAsset bindata= Resources.Load(“Texture”) as TextAsset; Texture2D tex = new Texture2D(1,1); tex.LoadImage(bindata.bytes); 2 assign values directly in the editor public TextAsset textFile; 3. The configuration file usually configures the attributes For example: Hero name, level, […]

  • Unity static variable cross scene operation


    Create two scenes and assign the staticvariant script at the same time, then press the key, h and j to switch the scenes continuously. You will find that the output number of the unity console increases continuously, and then remove the static. In this way, the result is 10. using UnityEngine; using System.Collections; using UnityEngine.SceneManagement; […]

  • Solution to the problem of not destroying objects in unit switching scenes


    When developing games with unity, we sometimes need some objects that do not need to be destroyed during scene switching. At this time, we can use the official dontdestroyonload() method, This method allows us not to destroy the scene during scene switching. But if you return to this scene (creating a scene of non destructible […]

  • Unity – detailed explanation of cooperation process


    1. Introduction The * * coroutine * * of unity is only a layer of encapsulation based on c#. In fact, yield is the keyword of c#. Unity coroutine is a function that can pause the execution of the coroutine, return to the main function immediately after the pause, execute the rest of the main […]

  • Unity game start interface making teaching


    Unity game start interface making teaching Step 1:Create a new sceneStep 2:Add a canvas object in the scene (right click in hierarchy – > UI – > canavas) Start button How to add a start button to:Right click on canvas – > UI – > buttonHow to add text to a button:The text component of […]

  • Operations using global variables in unity


    Create a script and enter the following code. The script does not need to be added to any object, and the globle variable can be called globally across scenes. using System.Collections; using System.Collections.Generic; using UnityEngine; public class Globle { public static int globle= 1; } Unlike many previous languages, C # has no global variables […]