Get the App
SLTechnology News&Howtos  ›  Development  › 

How to achieve shooting Mini Game with Unity

Shulou Source: shulou.com Published: 2022-06-01 05:02:46 10月05日 Update

This article mainly shows you "how to achieve shooting Mini Game Unity", the content is easy to understand, clear, hope to help you solve their doubts, the following let the editor lead you to study and learn "how to achieve Unity shooting Mini Game" this article.

Game screen display

This Mini Game only uses two UI interfaces, one is menu interface, the other is combat interface.

There are three modes of menu interface, which are general, difficult and hell.

The battle interface is very simple to brush wild monsters from both sides, and then the protagonist shoots them.

UI construction is very simple, only a background image using Image, plus a Text text input box, and then put the location!

The menu interface is as follows

Battle screen demonstration

Analysis of game code

This horizontal version of 2D shooting Mini Game, the core part only needs two scripts to complete, as soon as you learn, let's take a look at the code!

A script PlayerMove mounted to the player to control the player's left and right movements and jumps

There are two other ways to shoot, one is penetration and the other is slam! When you encounter a monster, you will lose blood.

When the player's blood volume is less than 0, it will jump out of the screen at the end of the game, very simple and clear logic!

The code is as follows, one does not have many lines, and the content of the code is also the most basic knowledge point of Unity. I believe anyone who knows a little can understand it.

The PlayerMove code is as follows

Using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;public class PlayerMove: MonoBehaviour {/ Health / public int HP; public Slider hpUI; / Animation / public Animator _ animator; / Kill / public static int jisha; public Text jishaUI; public Text jishaUIEnd / whether to jump / public bool isJump; / Game over UI / public GameObject ui; / / Use this for initialization void Start () {Time.timeScale = 1; jisha = 0; hpUI.maxValue = HP; hpUI.value = HP } / / Update is called once per frame void Update () {if (Input.GetKeyDown (KeyCode.Escape)) {UnityEngine.SceneManagement.SceneManager.LoadScene ("Menu");} if (HP

Tags: Mini Game code interface shooting players content life scripts two bullets pictures articles menus battles monsters attacks files methods times computers Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Information Shulou Tech Info Redmi OPPO Reno