49 lines
1.6 KiB
C#
49 lines
1.6 KiB
C#
using System;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using Unity.Mathematics;
|
|
using NodeCanvas.Framework;
|
|
using Drawing;
|
|
|
|
public class PlayerMovement : MonoBehaviour
|
|
{
|
|
// Raycasts
|
|
public RaycastHit forwardRay;
|
|
public RaycastHit leftRay;
|
|
public RaycastHit rightRay;
|
|
|
|
// References
|
|
private Player thisPlayer;
|
|
|
|
void Awake(){
|
|
thisPlayer = GetComponent<Player>();
|
|
}
|
|
|
|
void Update(){
|
|
Color forwardRayStatus = Color.red;
|
|
|
|
if (forwardRay.collider&& forwardRay.transform.gameObject.layer == LayerMask.NameToLayer("Environment")){ forwardRayStatus = Color.green;}
|
|
|
|
using (Draw.WithColor(forwardRayStatus)) {
|
|
Draw.Line(transform.position + transform.up, transform.position + transform.forward * 2.5f + transform.up);
|
|
}
|
|
}
|
|
|
|
void FixedUpdate(){
|
|
LayerMask environmentLayer = LayerMask.NameToLayer("Environment");
|
|
|
|
if (Physics.Raycast(transform.position + Vector3.up, transform.forward, out forwardRay, 2.5f, ~environmentLayer)){
|
|
thisPlayer.controls.graph.SendEvent<bool>("ForwardRay", true, null);
|
|
}
|
|
|
|
if (Physics.Raycast(transform.position + Vector3.up, transform.position + Vector3.left, out leftRay, maxDistance: 2f, ~environmentLayer )) {
|
|
thisPlayer.controls.graph.SendEvent("LeftRay", true, null);
|
|
}
|
|
|
|
if (Physics.Raycast(transform.position + Vector3.up, transform.position + Vector3.right, out rightRay, maxDistance: 2f, ~environmentLayer )) {
|
|
thisPlayer.controls.graph.SendEvent("RightRay", true, null);
|
|
}
|
|
}
|
|
}
|