1,What is a singleton?Give an example of using a singleton in a game
Singleton pattern , is a commonly used software design pattern. In its core structurecontains only one special class called a singleton.
Through the singleton mode, you canensure that there is only one instance of a class in the system span>And the instanceis easy to access to the outside world,thusconvenient to control the number of instancesAndconserve system resources.
If you want to have only one ,singleton pattern in the system is the best solution.
In the game ,methods and properties that need to be called frequently in multiple places and can only save one copy,can be defined as a singleton,such as a stand-alone game gold coins.
[csharp] view plaincopy
- //Hungry singleton mode
- public sealed class Singleton
- {
- private readonly static Singleton m_Instance = new Singleton();
- private Singleton( ){};
- public static GetInstance()
- {
- if(m_Instance == null)
- m_Instance = new Singleton();
- return m_Instance; ;
- }
- };
Second ,Unity’s method or idea of realizing day and night alternation? ;
1,You can directly rotate the light,
2,Or control the intensity of the light,Write a timer control.
3, can be changed by controlling a DirectionalLight,according to the passage of game time, Position and angle and brightness to simulate the sun, to achieve the change of day and night.
4,The easiest way to implement a plug-inTime of Day – Dynamic Sky Dome
5,When designing the game, see how to design it,You can hand it over to the artist to make two hemispheres, half day and half night, and use time to control the sphere constant turn. Whether it is too blunt or not depends on the artist.
6, you can also RenderSettings.skybox = xxx to render the skybox& #xff0c; The method of RenderSettings.ambientLight sets the ambient light to transition day and night.
Three , tower defense game ( ;Such as defending radish),how to store the path information of the map?The way to let the monster walk along the path is?
1,Put a cube at the key turning position of the map, store all key cubes The coordinates , store the path information of the map , after the monster reaches a cube, it rotates towards the position of the next cube, and then moves on.
2& #xff0c; can be pre-bakedThe baked waypoints store waypoint information,Let the monster useNavMeshAgent component,cooperate with the waypoint information of the map,for automatic navigation.
3,The location coordinates of the map can be stored in the form of an array ,The element of the array is Vector2,In the process of recording the location coordinates& #xff0c;The coordinates of the turning point must be recorded. The way to make the monster walk along the path is to move the character from one position to the adjacent position
4, The tower defense game is roughly divided into two parts. The first is the player construction area and the second is the monster activity area,Of course, the path information belongs to the activity area,We can divide the activity area into the starting point,activity Point , End point. Create a path script to define the current point ,next point, how to set the next point. Then hang the script on each node, and set the Tag label for each node. When the game starts, the path is drawn according to the nodes. Of course, this is just a simple implementation method.
There are many path algorithms for tower defense games ,greedy,A*,Dijkstra algorithm-yes Weighted edges , Bellman-Ford algorithm – supports negative weight , Floyd-Warshall algorithm, etc.
5,Stored by dividing the map into two-dimensional array,The path can be stored as the row and column index of the two-dimensional array according to the situation. Find the corresponding path according to the path index,control the monster to walk accordingly.
four& #xff0c; In “League of Legends” & #xff0c; how to judge whether a skill with displacement can pass through the wall & # xff1f; such as flashing over the wall / hitting the wall & # xff08; from the perspective of the program & # xff09; Some students said I don’t quite understand this question,Let me explain:Take flash as an example,some thick walls,can’t flash,but slightly thinner ones can. The question is ,how to judge,whether the thickness of this wall will allow me to flash past?