Table of contents
1. One-way platform
There are often one-way platforms in 2D platform games. Here we try to implement a one-way platform. First, we draw the new one-way platform into a new Tilemap, and then we find a component Platform Effector 2D, which is a one-way platform. Ready-made components All we have to do is set up this component.
Tick the Use by effects here
This creates a fan shape, which means we can step on the platform from above
Then cancel the use of the collider mask in the component Platform Effector 2D, and then click Use one-way
In this way we have realized a platform that can be jumped up from below.
2. Sound management
When we implemented sound effects, we mounted a lot of sound effect components for players, which was very difficult to manage, so we tried to use other methods for unified management
We create an empty object SoundManger and add code to it
Then add a sound source component. We hope that when we use the sound effect, we can automatically put that sound effect into this component, and then we delete all the sound effect components that were previously mounted on the game character.
Then we have to start writing code: (Here we take the jumping sound effect as an example)
public AudioSource audioSource;
public AudioClip jumpAudio;
We declare these two variables. The first variable is used to mount the AudioSource component we just added, and the other variable mounts the corresponding audio source fragment.
The code is implemented as follows:
public void JumpAudio()
{
audioSource.clip = jumpAudio;
audioSource.Play();
}
In this way, we can load the corresponding sound into the AudioSource when the corresponding sound effect is needed. We used to call this sound source directly in the character control script before.
So if we want to call now, we need to call functions of other classes, so we need to create an object of another class just like implementing the effect of enemies.
SoundManger soundManger = gameObject.GetComponent<SoundManger>();
soundManger.JumpAudio();
But this is actually not much more convenient than the original, so we use the static class method to achieve it, which will be much more convenient, but note that static classes will always occupy memory, which is also a bad place (Note: Static classes are generally not recommended to use )
Declare a static class entity in SoundManger
public static SoundManger instance;
Then initialize it at the beginning of the game
public void Awake()
{
instance = this;
}
In this way, the code of our character control can be changed to
SoundManger.instance.JumpAudio();
In this way, we have successfully accessed the function.
At the same time, we can also use instance to access variables in the class. We can change the variable to a private type, but we hope that while the private type is available, we can drag and drop Audio Clips in the Unity window to different variables. We need to add A header command:
[SerializeField]
private AudioClip jumpAudio
In this way, even if it is private, we can import audio clips by dragging and dropping on the Unity interface, and other audio effects can also be added using the above method (we don’t need to create a new AudioSource)
However, unified management will also bring some problems, that is, we cannot separate the volume processing of sound effects, and we cannot play sounds at the same time. Because we only have one AudioSource component, we still need to create multiple SoundManger groups to manage sound effects, so how to choose depends on personal choice.
3. Game generation
After so many days we are finally going to start generating our final game, we have to do some setup first
First in the upper left corner, go to File > Build Settings
Here you can choose the platform we generated
Here I chose the 64-bit Windows platform
Then click on Player Settings in the lower left corner
In this window, you need to fill in some basic information, such as game name, company, icon, cursor shape, etc. You can adjust this page according to your own needs. There is nothing that must be modified here, and you can modify it according to your needs.
We can enter the quality interface to set the level of image quality that players can choose
So we are ready, go back to the generate settings interface, click generate in the lower right corner
After waiting, the generation is complete, and we can try to play!
Link to the game I ended up making: https://github.com/night13567/The-adventures-of-Little-Fox