Projects / Game development

Unity Game Development

Small games and the code behind them.

Unity / C#Computer Game Design · Shenzhen UniversityCoursework & practice

Overview

A collection of my Unity work from Computer Game Design at Shenzhen University and related practice. Apple Picker explores catching, scoring, and game flow; Mission Demolition explores slingshot controls and projectile physics. Supporting scripting exercises and scene notes are collected below.

Games

Two prototypes

Code & scene notes

Short exercises and setup notes collected alongside the games.

Collections & object lifecycles

List operations, cube creation, shrinking, and deferred removal.

Code excerpt & notes

Assets/CubeSpawner3.cs


    void Update()
    {
        List<GameObject> removeList = new List<GameObject>(); // 创建一个列表用于存储需要移除的立方体

        foreach (GameObject goTemp in gameObjectList)
        {
            float scale = goTemp.transform.localScale.x; // h: 获取当前立方体的大小
            scale *= scalingFactor; // 缩小立方体
            goTemp.transform.localScale = Vector3.one * scale;

            if (scale <= 0.1f) // 如果尺寸小于0.1f...
            {
                removeList.Add(goTemp); // 则加到removeList中
            }
        }
Browse source files

The file CubeSpawner3.cs declares CubeManager, so its name needs alignment before attaching it as a MonoBehaviour in Unity. ArrayEx.cs and ArrayEx1.cs are empty exercise stubs in this snapshot.

Hello World / cube spawning

Prefab instantiation, random colors, and frame-based object lifetimes.

Code excerpt & notes

Assets/CubeSpawer3.cs

    // 每帧都会调用一次 Update()
    void Update() {
        numCubes++;                              // 使立方体数目增加1
        GameObject gObj = Instantiate(cubePrefabVar) as GameObject;   // 实例化一个新的立方体

            gObj.name = "Cube " + numCubes;  // c
        Color c = new Color(Random.value, Random.value, Random.value);  // d
        gObj.GetComponent<Renderer>().material.color = c;
        gObj.transform.position = Random.insideUnitSphere;
        gameObjectList.Add(gObj);

        List<GameObject> removeList = new List<GameObject>();

        foreach (GameObject goTemp in gameObjectList) {

            float scale = goTemp.transform.localScale.x;
            scale *= scalingFactor;
            goTemp.transform.localScale = Vector3.one * scale;

            if (scale <= 0.1f) {  // 如果尺寸小于 0.1f.....
Browse source files

The original filename CubeSpawer3.cs differs from its CubeSpawner3 class name. This should be corrected before attaching the script in Unity. Spawning and shrinking are frame-based, not time-normalized.

Boids / scene notes

An Attractor, BoidAnchor, and Boid prefab setup. This snapshot contains no custom flocking scripts.

Code excerpt & notes

Assets/Scenes/_Scene_().unity

  serializedVersion: 6
  m_Component:
  - component: {fileID: 1860228899}
  m_Layer: 0
  m_Name: BoidAnchor
  m_TagString: Untagged
  m_Icon: {fileID: 0}
  m_NavMeshLayer: 0
  m_StaticEditorFlags: 0
  m_IsActive: 1
--- !u!4 &1860228899
Transform:
  m_ObjectHideFlags: 0
Browse scene and prefab files

Scene setup only. There is no verified flocking simulation or playable demonstration in this snapshot.

← All projects