Skip to content

Instantly share code, notes, and snippets.

View whoisryosuke's full-sized avatar
👾
Going deep with game development

Ryosuke whoisryosuke

👾
Going deep with game development
View GitHub Profile
<div id="output" style="background:green;min-height:40px">
</div>
import { useEffect, useState } from "react"
// Modified the useKeyPress from useHooks: https://usehooks.com/useKeyPress/
// Takes a `pressMethod` that will run continuously "every frame" (1/60 second - not locked tho)
// And also accepts a `downMethod` and `upMethod` for a single call
// And still returns a simple true/false for the keypress for convenience/use in React
// Ideally all the methods should be an properties of 1 object so user doesn't have to set noop functions to get deeper params
export default function useKeyPress(targetKey: string, pressMethod?: () => void, downMethod?: () => void, upMethod?: () => void): boolean {
// State for keeping track of whether key is pressed
const [keyPressed, setKeyPressed] = useState(false)
@whoisryosuke
whoisryosuke / platform-check.js
Created December 29, 2021 19:28
JS - Check user platform OS - client side / frontend only - https://stackoverflow.com/a/19176790
var OSName = "Unknown";
if (window.navigator.userAgent.indexOf("Windows NT 10.0")!= -1) OSName="Windows 10";
if (window.navigator.userAgent.indexOf("Windows NT 6.3") != -1) OSName="Windows 8.1";
if (window.navigator.userAgent.indexOf("Windows NT 6.2") != -1) OSName="Windows 8";
if (window.navigator.userAgent.indexOf("Windows NT 6.1") != -1) OSName="Windows 7";
if (window.navigator.userAgent.indexOf("Windows NT 6.0") != -1) OSName="Windows Vista";
if (window.navigator.userAgent.indexOf("Windows NT 5.1") != -1) OSName="Windows XP";
if (window.navigator.userAgent.indexOf("Windows NT 5.0") != -1) OSName="Windows 2000";
if (window.navigator.userAgent.indexOf("Mac") != -1) OSName="Mac/iOS";
if (window.navigator.userAgent.indexOf("X11") != -1) OSName="UNIX";
@whoisryosuke
whoisryosuke / index.html
Created December 28, 2021 19:31 — forked from vhashimotoo/index.html
Dialog Invoke Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Dialog Example</title>
</head>
<body>
<h1>Dialog Example</h1>
<button id="execute-dialog">Click to show dialog</button>
@whoisryosuke
whoisryosuke / fetch-post-request.js
Created November 29, 2021 08:35
JS - Fetch POST request as async function
(async () => {
const rawResponse = await fetch('https://httpbin.org/post', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({a: 1, b: 'Textual content'})
});
const content = await rawResponse.json();
@whoisryosuke
whoisryosuke / gist:3c482e593dee25e2b9d52f0f850b91ba
Created November 22, 2021 19:44 — forked from kany/gist:3714996
Git Repo changes ssh fingerprint - how to update your known_hosts file
1) Open known_hosts file and look for the invalid host
nano ~/.ssh/known_hosts
2) Remove the line that has the invalid host. Should be the same host in your .git/config of your repo
ssh-keygen -R [dev.blahblah.com]:1234
3) Pull from repo
git pull
4) You should see something similar to this. Answer 'yes' when asked.
@whoisryosuke
whoisryosuke / MouseLook.cs
Last active November 18, 2021 22:24
Unity - Basic 3D/FPS Character and Camera Movement + Jumping - based on Brackeyes video: https://www.youtube.com/watch?v=_QajrabyTJc
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseLook : MonoBehaviour
{
private bool mouseLock = true;
public float mouseSensitivity = 100f;
public Transform playerBody;
@whoisryosuke
whoisryosuke / PointerExample.cs
Created November 18, 2021 22:15
Unity - Detect input on canvas elements using EventSystem event interfaces (e.g. IPointerClickHandler) -- via: http://answers.unity.com/answers/1095070/view.html
using UnityEngine;
using UnityEngine.EventSystems; // 1
public class PointerExample : MonoBehaviour
, IPointerClickHandler // 2
, IDragHandler
, IPointerEnterHandler
, IPointerExitHandler
// ... And many more available!
{
@whoisryosuke
whoisryosuke / CheckClicks.cs
Created November 18, 2021 22:13
Unity - Detect click on canvas using graphic raycaster -- via: http://answers.unity.com/answers/1526703/view.html
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class CheckClicks : MonoBehaviour
{
// Normal raycasts do not work on UI elements, they require a special kind
GraphicRaycaster raycaster;
@whoisryosuke
whoisryosuke / PlayerLocomotionController.cs
Last active October 12, 2021 00:27
Unity - 3D Player Movement using Unity's Player Input package - via: https://www.youtube.com/watch?v=537B1kJp9YQ
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
// Handles actual movement of character + triggering things like animation
// This game has a "shooting mode" which is activated by Left Shift
// So you'll see shooting logic as well
public class PlayerLocomotionController : MonoBehaviour