Scrappy Squirrel

Link to Itch.io

Scrappy Squirrel Game

This is one of my very first game projects that I have worked on. This project really helped me understand the basics of Unity and how to use it. It helped me combine what I have learned in computer science with Unity.

Code Snippet: Random Position Generator

Here's a piece of code I did from the Scrappy Squirrel project:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.U2D;

public class randomPosition: MonoBehaviour
{
    public int numberToSpawn;
    public List<GameObject> spawnPool;
    public List<GameObject> quadPool;
    
    void Start()
    {
        SpawnObject();
    }

    private int ramdomQuad(){
        int ramdomQuad = Random.Range(0, quadPool.Count);
        return ramdomQuad;
    }

    public void SpawnObject(){
        GameObject ToSpawn;

        float screenX, ScrrenY;
        Vector2 pos;
        for(int i = 0; i < numberToSpawn; i++){
            int ramdomQuadnum = ramdomQuad();
            MeshCollider c = quadPool[ramdomQuadnum].GetComponent<MeshCollider>();
            ramdomQuadnum = Random.Range(0, quadPool.Count);

            ToSpawn = randomItem();

            screenX = Random.Range(c.bounds.min.x, c.bounds.max.x);
            ScrrenY = Random.Range(c.bounds.min.y, c.bounds.max.y);
            pos = new Vector2(screenX, ScrrenY);

            Instantiate(ToSpawn, pos, ToSpawn.transform.rotation);
        }
    }

    private void destoryObject(){
        foreach(GameObject obj in GameObject.FindGameObjectsWithTag("Spawneable")){
            Destroy(obj);
        }
    }

    private GameObject randomItem()
    {
        int temp = Random.Range(0, 11);
        if(temp == 10)
        {
            return spawnPool[1];
        }
        else
        {
            return spawnPool[0];
        }
    }
}

It selects random positions within predefined quadrants and instantiates game objects from a spawn pool. This adds variety and challenge to the gameplay. At that time this was all very new to me, and it was a great lesson on how to do rearch and implement new features.