Skip to content

Instantly share code, notes, and snippets.

@leestuartx
leestuartx / UDP_GyroSend.cs
Created April 2, 2015 22:10
Use IOS or Android as a mobile controller in Unity (Send)
using UnityEngine;
using System.Collections;
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
public class UDP_GyroSend : MonoBehaviour {
@BichengLUO
BichengLUO / GravityCamera.cs
Last active November 30, 2021 00:37
A Unity3D script for rotating the camera according to the device's accelerometer
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
public class GravityCamera : MonoBehaviour
{
public GameObject target;
public Vector3 centerOffset;
public float sensitivity = 1000;
@kormyen
kormyen / VrModeSwitch.cs
Last active October 17, 2020 10:04
Unity3D script for switching between Cardboard VR mode and "magic window" (non-vr-36-mode). For reference GyroCamera.cs see https://gist.github.com/kormyen/a1e3c144a30fc26393f14f09989f03e1 . For referenced VREyeRaycaster.cs see Unity VR samples https://www.assetstore.unity3d.com/en/#!/content/51519
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.VR;
using VRStandardAssets.Utils;
public class VrModeSwitch : MonoBehaviour
{
// REFERENCE
[SerializeField] private GyroCamera _gyroControl;
@petecleary
petecleary / CompassLocation.cs
Created October 17, 2017 06:36
Unity mobile compass controller, how to enable and rotate the transform based on the magnetic heading
using System;
using UnityEngine;
using UnityEngine.UI; //required for Input.compass
public float compassSmooth = 0.5f;
private float m_lastMagneticHeading = 0f;
public class CompassController : MonoBehaviour {
// Use this for initialization
void Start () {
@roydejong
roydejong / NativeWinAlert.cs
Last active June 4, 2024 09:03
Unity: NativeWinAlert (Windows MessageBox / Alert Dialog for Unity games)
using System;
using System.Runtime.InteropServices;
/// <see>https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-messagebox</see>
public static class NativeWinAlert
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern System.IntPtr GetActiveWindow();
public static System.IntPtr GetWindowHandle()
@RyanWilson7
RyanWilson7 / RotateAxisOnCompass.cs
Last active November 26, 2020 06:48
Unity script for rotating a GameObjects transform to compass direction on a given axis
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotateAxisOnCompass : MonoBehavior
{
enum Axis { x, y, z }
[SerializeField] private Axis rotateAxis;
[SerializeField] private float compassSmooth;
private float lastMagneticHeading;
private void Start()