Skip to content

Instantly share code, notes, and snippets.

View benthroop's full-sized avatar

Ben Throop benthroop

View GitHub Profile
@benthroop
benthroop / ClampDirection.cs
Last active August 8, 2022 21:50
Unity Clamp Direction Angle
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class ClampDirection : MonoBehaviour
{
public Transform targetObj;
public float clampAngle;
@benthroop
benthroop / OMGMoveTheCursorOnPlayMode.cs
Created February 5, 2023 20:56
Fix a Unity annoyance with mouse cursor and play mode button.
/*
This fixes an issue you'd encounter if...
1. You hit the play button with the mouse cursor.
2. You lock/hide the mouse cursor.
3. You click a mouse button (presumably right or middle mouse) to show the mouse cursor again.
In this case, you will find that the mouse cursor is still on the play button, and the click which unhides the cursor
will press the play button, thus stopping the editor. This happened to me most often when I would use a gamepad after
hitting play, but would want to edit something via the mouse. Not a common issue, but once you accidentally stop your
@benthroop
benthroop / createterraindata.cs
Created July 18, 2024 12:06
Function to make a new TerrainData and assign it to a selected Terrain GameObject.
//Two editor functions you can put wherever you like
public void CreateTerrainData()
{
//get the selected terrain gameobject
//create a terrain asset in the folder selected in the project view
//name the terrain data the same as the gameobject
//assign the terraindata to the terrain and the terraincollider
var t = Selection.activeGameObject.GetComponent<Terrain>();