41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
using System;
|
|
using Syntriax.Modules.Trigger;
|
|
using UnityEngine;
|
|
|
|
namespace Syntriax.Modules.Movement.Samples
|
|
{
|
|
public class MovementInputSample : MonoBehaviour
|
|
{
|
|
private IMovementController movementController = null;
|
|
private Rigidbody2D rigid = null;
|
|
private IGroundTrigger groundTrigger = null;
|
|
|
|
private void Start()
|
|
{
|
|
movementController = GetComponent<IMovementController>();
|
|
groundTrigger = GetComponentInChildren<IGroundTrigger>();
|
|
rigid = GetComponent<Rigidbody2D>();
|
|
}
|
|
|
|
private Vector3 input = Vector3.zero;
|
|
private void Update()
|
|
{
|
|
input = Vector3.zero;
|
|
input.x = Input.GetAxis("Horizontal");
|
|
input.y = Input.GetAxis("Vertical");
|
|
|
|
movementController.Move(input);
|
|
|
|
if (Input.GetKeyDown(KeyCode.Space) && groundTrigger.IsTrigerred)
|
|
Jump();
|
|
}
|
|
|
|
private void Jump()
|
|
{
|
|
Vector2 velocity = rigid.velocity;
|
|
velocity.y = 10f;
|
|
rigid.velocity = velocity;
|
|
}
|
|
}
|
|
}
|