• [初学Untiy]SPACE SHOOTER TUTORIAL


    开始时间:2016年7月31日21:37:37

    参考链接:http://unity3d.com/learn/tutorials/projects/space-shooter-tutorial

    The player GameObject

    add Rigidbody Component

    To detect collision, the physics engine, through the rigid body, needs to know the volume of our objects.We need to know how much space these objects take up in our game to calculate the collisions. We give this information to the rigid body by using a cage that we wrap around our game objects. This cage defines the volume of that object. The cage is called a Collider.

    add CapsuleCollider Component

    remove it

    add MeshCollider Component, select "Convex"

    The Mesh Collider component will not participate properly in physics
    collisions and will not be visible in the scene view unless we select
    “Convex” on the Mesh Collider Component.
    There are some limitations when using the Mesh Collider. Non-convex Mesh Colliders are only supported on GameObjects without a rigidbody. If you want to use a Mesh Collider on a rigidbody, it needs to be marked as Convex.

    select "Is Trigger"

    We simply need our collision to trigger an action.

    打卡:2016年8月1日21:25:18

    CAMERA AND LIGHTING

    Set Camera

    • Our game needs to feel like an upright arcade game. These did not have any perspective. So we will choose orthographic as our projection mode.
    • set Size to 10
    • We want the player in the origin, so we move the camera to let player at the bottom at the start.

    by default in Unity 5, a Skybox is included in thescene. This skybox will influence the ambient light affecting the shipand will be used as the background image by the Main Camera.

    Set Light
    main light, a fill light, a rim light

    We can organize our hierarchy by using empty Game Objects.
    And It is important to reset the transform of this empty game object.

    打卡:2016年8月2日14:08:19(昨天看的有点少)

    Adding a background

    add a quad object, rotate, remove mesh collider component.

    What is a matte paint?
    Glossy and flat (or matte) are typical extreme levels of glossiness of a finish. Glossypaints are shiny and reflect most light in the specular (mirror-like) direction, while onflat paints most of the light diffuses in a range of angles. The gloss level of paintcan also affect its apparent colour.

    1. Mesh Filter holds the mesh data: Quad.
    2. The Mesh Renderer renders that mesh using the materials in the Mesh Renderer's Materials Array.
    3. The renderer is only able to use a Texture if it's a part of a Material.
      In this case, we did not create a material, we simply dragged the texture on the Quad. It was Unity that created the Material for us.
    4. For our Background, let's change the Shader. Let's choose Unlit/Texture for the Shader on the nebula materail. Now our Background is independent of our lighting system and it display the texture exactly as it looks in the original image and it uses no lights at all.

    move the background down.

    读了Lighting Overview

    Moving the Player

    add Script named PlayerController.cs to Player GameObject

    "camelCase" isn't PascalCase, but "PascalCase" is.

    use Input.GetAxis() to 得到运动的分量 来 设置 rb.velocity() 从而使飞船运动。

    设置飞船运行的限制区域
    学习 Class Boundary 的用法

    Mathf - A collection of common math functions.

    Mathf.Clamp(float value, float min, float max)
    将value限制在 min 和 max 之间

    设置 飞船的 tilt,让飞船在左右移动的时候有适当的倾斜。

    Quaternion Euler(float x, float y, float z)
    Returns a rotation that rotates z degrees around the z axis, x degrees around the x axis, and y degrees around the y axis (in that order).

    Creating shots

    Creating shots by assembling artwork, physics components and custom C# code.

    1. Create a Object named Bolt, this will be the parent object for our shot.

    We are going to separate the game logic from our visual effect of the shot. This will allow us to easily make new weapons with different visual effects by reusing the parent game object with the logic and replacing the visual effect layer.

    1. Create a Quad VFX to hold the visual effect image. Add the VFX game object as a child of Bolt.

    2. Create a Material fx_bolt_orange for the Quad VFX. Drag the Material on to the Quad.

    3. Look at Quad VFX game object, We Change the shader on the material fx_bolt_orange to Particles - Additive

    With shader particles/additive, black has a value of 0 and will add nothing to the scene. And white has a value of 255 on all channels and will add full white to the scene. All of the other colours will be added on top of the existing background. This will give us a strong, hot laser bolt.

    We can also change Shader to mobile/particle/additive.
    In general the mobile shader will be more efficient with our game's resource budget, but in some cases may sacrifice either quality or control. The main control that we will lose by using this mobile shader is the ability to change the tint colour, which we don't need on our laser bolt.

    with our visual effect set up, let's move on to setting up our logic.也就是说配置 Bolt 对象。
    5. Add rigid body component to Bolt game object.
    6. Remove collider component of the VFX game object.
    7. Add Capsule Collider to Bolt game object. And adjust it's size and orientation.
    8. Click is trigger of this collider to make this collider a trigger collider.
    9. Add Mover.cs component to Bolt game object.
    10. our player is going to shoot many copies or clones of this shot, so let's save this game object as a prefab. And we set the speed value in this prefab not the INSTANCE in the scene.
    11. delete our working instance of Bolt from the scene.
    12. to test the Bolt, as we don't have any shooting code, we simply drag the copies of the prefab into the hierarchy window while the game is running.

    Shooting shots

    Writing the code and setting up the scene to shoot shots.

    What we need to do is instantiate a copy of clone of this Shot prefab when we hit a button or click a mouse during our gameplay.

    1. create a empty game object named Shot Spawn. We can use this empty game object's transform as a spawn point in our game. This spawn point should move with our player ship. So let's drag Shot Spawn on to our player game object and drop it as a child. As it's a child of the player ship, our Shot Spawn's position will be relative to the player ship.
    2. drag the Shot Spawn out along it's Z axis until it's in front of the ship.

    打卡:2016年8月3日20:29:59

    Boundary

    Creating a bounding box to destroy any object that leaves the game area.

    We are going to create a box around our game and we will destroy these shots as they leave the box.(所以我们使用 OnTriggerExit(Collider))

    注:The number of units from the top of the screen to the bottom is always twice the value of our camera's orthographic size.

    Creating hazards

    Create an asteroid hazard to challenge the player.

    注:We will have a parent game object for the logic and the artwork will be a child.

    让小行星随机旋转用到 Random.insideUnitSphere
    Returns a random point inside a sphere with radius 1 (Read Only).

    Set Angular Drag value to 0. 避免小行星停止自转。

    Write trigger collider code for our 2 colliders to have any effect.

    我们发现小行星由于和Boundary接触而消失,为了避免这一效果,tag our boundary.

    // DestroyByContact.cs
    using UnityEngine;
    using System.Collections;
    
    public class DestroyByContact : MonoBehaviour
    { 
        void OnTriggerEnter(Collider other)
        {
            // Debug.Log(other.name);
            if(other.tag == "Boundary") // 当 other 的 tag 是 Boundary 的时候,跳过
            {
                return;
            }
            Destroy(other.gameObject);  // Destroy the laser bolt when it hits the asteroid.
            Destroy(gameObject);        // Destroy the asteroid itself.
        }
    }
    

    Explosions

    Add explosions to the scene when hazards or the player is destroyed.

  • 相关阅读:
    web框架开发-Django模型层(1)之ORM简介和单表操作
    web框架开发-模板层
    生产者-消费者模式
    不变模式
    SynchronousQueue
    ThreadLocal
    锁的优化以及Java虚拟机对锁优化所做的努力
    随机数据结构:跳表(SkipList)
    数据共享通道:BlockingQueue
    CopyOnWriteArrayList
  • 原文地址:https://www.cnblogs.com/ice-mj/p/5734721.html
Copyright © 2020-2023  润新知