Skip to content

Instantly share code, notes, and snippets.

@andywatts
Created April 16, 2020 15:33
Show Gist options
  • Save andywatts/bca7437305c576be97883b860a28e744 to your computer and use it in GitHub Desktop.
Save andywatts/bca7437305c576be97883b860a28e744 to your computer and use it in GitHub Desktop.
using UnityEngine;
using CMF;
public class CameraControl : CameraInput
{
public Controls controls; // ScriptableObject with InputActions; Provides for global en|disabling InputMaps between menu/game/dash
Vector2 look;
void OnEnable() { controls.Value.CharacterController.Enable(); }
void OnDisable() { controls.Value.CharacterController.Disable(); }
void Awake()
{
controls.Value.CharacterController.Look.performed += ctx => { look = ctx.ReadValue<Vector2>(); };
controls.Value.CharacterController.Look.canceled += ctx => { look = new Vector2(); };
}
public override float GetHorizontalCameraInput()
{
return look.x;
}
public override float GetVerticalCameraInput()
{
return -look.y;
}
}
using UnityEngine;
using UnityEngine.InputSystem;
[CreateAssetMenu(menuName = "YourMamaSoFat/Controls")]
public class Controls : ScriptableObject
{
[Header("Controls")]
public InputActions Value;
void OnEnable()
{
Value = new InputActions();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Entities;
using Oasis;
using Oasis.Protobufs;
using CMF;
public class PlayerControls : CharacterInput
{
public Controls controls; // ScriptableObject with InputActions; Provides for global en|disabling InputMaps between menu/game/dash
Vector2 movement;
bool jump;
void OnEnable() { controls.Value.CharacterController.Enable(); }
void OnDisable() { controls.Value.CharacterController.Disable(); }
void Awake()
{
controls.Value.CharacterController.Move.performed += ctx => { movement = ctx.ReadValue<Vector2>(); };
controls.Value.CharacterController.Move.canceled += ctx => { movement = new Vector2(); };
controls.Value.CharacterController.Jump.started += ctx => { jump = true; };
controls.Value.CharacterController.Jump.canceled += ctx => { jump = false; };
}
public override float GetHorizontalMovementInput()
{
return movement.x;
}
public override float GetVerticalMovementInput()
{
return movement.y;
}
public override bool IsJumpKeyPressed()
{
return jump;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment