Skip to content

Instantly share code, notes, and snippets.

View unitycoder's full-sized avatar
‏‏‎

mika unitycoder

‏‏‎
View GitHub Profile
@unitycoder
unitycoder / RunMode.cs
Created June 19, 2024 11:39
How to know if a script is running inside Unity Editor when using Device Simulator
// https://forum.unity.com/threads/how-to-know-if-a-script-is-running-inside-unity-editor-when-using-device-simulator.921827/
public static class RunMode {
  public enum ApplicationRunMode {
    Device,
    Editor,
    Simulator
  }
  public static ApplicationRunMode Current {
    get {
      #if UNITY_EDITOR
@unitycoder
unitycoder / FixedUpdateScheduler.cs
Created June 19, 2024 05:56
Better FixedUpdate
// https://forum.unity.com/threads/stable-fixedupdate-scheduling-plus-motion-interpolation-global-solution.1547513/
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// This script schedules FixedUpdate() calls globally according to the Hysteresis loop.
///
/// How to use FixedUpdateScheduler:
/// Simply attach this script to a SINGLE object in the scene.
@unitycoder
unitycoder / Extension Methods for LayerMask.cs
Last active June 20, 2024 19:58
Check if GameObject is in Layer or check if Layer is in LayerMask
// https://forum.unity.com/threads/extension-methods-for-layermask.1605513/
public static void Add(ref this LayerMask mask, int layer)
{
    mask |= (1 << layer);
}
 
public static void Remove(ref this LayerMask mask, int layer)
{
    mask &= ~(1 << layer);
}
@unitycoder
unitycoder / windows 11 notes
Last active June 3, 2024 10:58
Windows 11 Notes
### setup without microsoft account
- need to be completely disconnected from internet (bypass oobe doesnt work anymore) : Open CMD, "ncpa.cpl" then disable network device. Restart
@unitycoder
unitycoder / jira-ux-issues.md
Created May 23, 2024 14:27
Whats wrong with JIRA (ux issues)

UX

  • When someone posts image into exisiting issue, i cannot see who posted it and it doesnt appear in the message they have sent. (instead, it appears as general attached for the whole issue!) I Have no idea who posted it and i dont understand what image the message refers "what you you think of this image?" (what image???)
@unitycoder
unitycoder / MakeSphereHemisphere.cs
Created May 21, 2024 19:13
Script to create a hemisphere mesh
// https://forum.unity.com/threads/script-to-create-a-hemisphere-mesh.496720/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MakeSphereHemisphere : MonoBehaviour
{
[Header("Sphere Options")]
public float radius = 1f;
@unitycoder
unitycoder / FBXAnimationOrganizer.cs
Created May 10, 2024 07:07
FBX Animation Organizer
// https://forum.unity.com/threads/reordering-fbx-animation-clips.1168847/#post-9825564
/*******************
WARNING: MAKE SURE YOUR METADATA FILES ARE BACKED UP WITH VERSION CONTROL BEFORE USING
Installation:
Copy this C# script into Scripts\Editor.
Usage:
1) To open, go to Window -> FBX Animation Organizer
2) Enter the local directory location of your fbx meta files in the "Directory" field (Right click on the folder in Project window -> Copy Path)
3) Select the meta file to edit from the "File" dropdown
@unitycoder
unitycoder / ResetDraggable.cs
Created May 7, 2024 12:21
Reset Draggable object, unless its placed on socket
using System.Collections;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;
public class ResetDraggable : MonoBehaviour
{
XRGrabInteractable grabInteractable;
Vector3 origPos;
Quaternion origRot;
@unitycoder
unitycoder / SetCardPosition.cs
Created May 6, 2024 12:04
align cards on circle edge
// https://discussions.unity.com/t/need-help-with-positioning-while-object-is-rotated/344542/2
private void SetCardPosition(int index)
{
//The angle is based on how far the card is from the midpoint of the hand.
//Note that the midpoint will either be a whole number or x.5
float midpoint = (cards.Count-1) / 2f;
float angle = angleDelta * (midpoint - index);
//Positive angles rotate counterclockwise, negative angles rotate clockwise
cards[index].transform.eulerAngles = new Vector3(0, 0, angle);
@unitycoder
unitycoder / ReelBack.cs
Created April 29, 2024 04:47
Reel Line made from points back
// https://forum.unity.com/threads/coding-a-2d-extendable-and-retractable-fishline.1586673/#post-9801981
private void ReelBack(List<Vector3> points, float reelValue)
{
    if (reelValue <= 0)
        return;
 
    Vector3 origin = points[0];
    float reel = reelValue;
 
    // find cut point