Skip to content

Instantly share code, notes, and snippets.

View Matthew-J-Spencer's full-sized avatar

Matthew Spencer Matthew-J-Spencer

View GitHub Profile
@Matthew-J-Spencer
Matthew-J-Spencer / tide-logogroup.svg
Created February 25, 2019 03:51
Tide Logo Group
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Matthew-J-Spencer
Matthew-J-Spencer / Dragger.cs
Created January 25, 2021 13:23
A simple drag and drop script for Unity. Follow along: https://youtu.be/Tv82HIvKcZQ
using UnityEngine;
public class Dragger : MonoBehaviour {
private Vector3 _dragOffset;
private Camera _cam;
[SerializeField] private float _speed = 10;
void Awake() {
public class NetworkManager : MonoBehaviour {
private void Start() {
StartCoroutine(MakeRequests());
}
private IEnumerator MakeRequests() {
// GET
var getRequest = CreateRequest("https://jsonplaceholder.typicode.com/todos/1");
yield return getRequest.SendWebRequest();
@Matthew-J-Spencer
Matthew-J-Spencer / SaveManager.cs
Created March 10, 2021 08:31
A save manager for your Unity game. Tutorial: https://www.youtube.com/watch?v=Lt-AiGbHN9g
public class SaveManager : MonoBehaviour {
public static SaveData SaveData;
private static string SavePath => $"{Application.persistentDataPath}/save.game";
private BinaryFormatter _formatter = new BinaryFormatter();
void Start() {
Load();
}
public class Turret : MonoBehaviour {
private Camera _cam;
[SerializeField,Range(1,100)] private float _rotationSpeed = 1;
[SerializeField] private Projectile _projectilePrefab;
[SerializeField] private Transform _spawnPoint;
void Awake()
{
_cam = Camera.main;
}
@Matthew-J-Spencer
Matthew-J-Spencer / GridManager.cs
Last active May 10, 2021 06:01
GridManager.cs
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GridManager : MonoBehaviour {
[SerializeField] private int _width, _height;
[SerializeField] private Tile _tilePrefab;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tile : MonoBehaviour {
[SerializeField] private Color _baseColor, _offsetColor;
[SerializeField] private SpriteRenderer _renderer;
[SerializeField] private GameObject _highlight;
public void Init(bool isOffset) {
public class PlayerController : MonoBehaviour {
[SerializeField] private Rigidbody _rb;
[SerializeField] private float _speed = 5;
[SerializeField] private float _turnSpeed = 360;
private Vector3 _input;
private void Update() {
GatherInput();
Look();
}
public class SlerpySlerp : MonoBehaviour {
[SerializeField] private Transform _start, _center, _end;
[SerializeField] private int _count = 15;
private void OnDrawGizmos() {
foreach (var point in EvaluateSlerpPoints(_start.position, _end.position, _center.position,_count)) {
Gizmos.DrawSphere(point, 0.1f);
}
Gizmos.color = Color.red;
Gizmos.DrawSphere(_center.position, 0.2f);
using UnityEngine;
public class GunSprint : MonoBehaviour {
[SerializeField] private Bullet _bulletPrefab;
[SerializeField] private Transform _spawnPoint;
[SerializeField] private ParticleSystem _smokeSystem;
[SerializeField] private LayerMask _targetLayer;
[SerializeField] private float _bulletSpeed = 12;
[SerializeField] private float _torque = 120;