Skip to content

Instantly share code, notes, and snippets.

View UtMan88's full-sized avatar

Keith Maggio UtMan88

View GitHub Profile
@UtMan88
UtMan88 / ArcDetect.cs
Created November 10, 2019 16:31
Create an array of points to be used as turrets, and detect if a point is within a certain angle range.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ArcDetect : MonoBehaviour
{
[System.Serializable]
public class Turret
{
@UtMan88
UtMan88 / AngleLerp.cs
Last active October 4, 2021 19:42
Originally posted by BakonGuy at Unity Answers: https://answers.unity.com/questions/775784/lerping-euler-angles-make-entire-spin.html, this script helps lerp around angles that potentially pass into the negatives, which would cause objects to spin rapidly.
//Properly Lerp between two angles
Vector3 AngleLerp(Vector3 StartAngle, Vector3 FinishAngle, float t)
{
float xLerp = Mathf.LerpAngle(StartAngle.x, FinishAngle.x, t);
float yLerp = Mathf.LerpAngle(StartAngle.y, FinishAngle.y, t);
float zLerp = Mathf.LerpAngle(StartAngle.z, FinishAngle.z, t);
Vector3 Lerped = new Vector3(xLerp, yLerp, zLerp);
return Lerped;
}
@UtMan88
UtMan88 / SetActiveOnEnable.cs
Created December 19, 2018 22:40
When the object in the scene becomes enabled, all objects in "observedObjects" will become Enabled/Disabled based on their SetActiveOnEnable flag. Handy for turning things on/off when starting a scene.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SetActiveOnEnable : MonoBehaviour {
[System.Serializable]
public class ObservedObjects
{
public GameObject gameObject;
@UtMan88
UtMan88 / Simple2DSteer.cs
Last active December 14, 2020 15:03
Simple 2D Steering Algorithm for Unity.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SimpleSteerUtility
{
// This is more of an example to show how the interface functions can be used in a very simple manner.
// Or, this can be your one-stop shop for a single function call in your Update function.
public static void SimpleSteer(ref Quaternion rotation, // ex: transform.rotation
ref Transform transform,
@UtMan88
UtMan88 / Steering.cpp
Created September 26, 2017 00:42
ArduBoy Mock-Steering (Seek) Algorithm
struct FPoint {
float x; /**< The X coordinate of the point */
float y; /**< The Y coordinate of the point */
};
FPoint steer(const FPoint& target, const FPoint& pos, const FPoint& curForward) {
// Direction to target
FPoint dir;
dir.x = target.x - pos.x;
dir.y = target.y - pos.y;
using UnityEngine;
using System.Collections;
/// <summary>
/// This was just a quick-and-dirty tool when inside the Unity Editor.
/// Need an Icon on something? Throw this on it, assign a texture (via URI string), done.
/// </summary>
public class GizmoIcon : MonoBehaviour {
public string IconFile;
@UtMan88
UtMan88 / CloudGenerator.cs
Last active December 5, 2022 09:22
Unity script that generates random "clouds" (or whatever you want the prefab to be) along an X-Z plane using PerlinNoise.
using UnityEngine;
using System.Collections;
/// <summary>
/// Generates random "clouds" (or whatever you want the prefab to be) along an X-Z plane
/// using PerlinNoise.
/// </summary>
public class CloudGenerator : MonoBehaviour {
/// <summary>