Last active
October 6, 2020 21:11
-
-
Save leventeren/7c323a735403f90b20a6cbf2f5016ae9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class RayController : MonoBehaviour{ | |
public bool debug; | |
RaycastHit hit; | |
public Transform from; | |
public Transform to; | |
public Ray Ray{ | |
get | |
{ | |
return new Ray(from.position, to.position - from.position); | |
} | |
} | |
public float distance = Mathf.Infinity; | |
public LayerMask layerMask; | |
private void Update(){ | |
RaycastHit hit; | |
if (Physics.Raycast(Ray, out hit, distance, layerMask)){ | |
Debug.Log(hit.transform.name); | |
//PlayerController.instance.manModel.transform.position = new Vector3(PlayerController.instance.manModel.transform.position.x, hit.point.y+(PlayerController.instance.manModel.transform.position.y/2), PlayerController.instance.manModel.transform.position.z); | |
} | |
} | |
private void OnDrawGizmos(){ | |
if (debug){ | |
var validDebugDistance = distance == Mathf.Infinity ? 99999 : distance; | |
Gizmos.color = Color.red; | |
Gizmos.DrawRay(Ray.origin, Ray.direction * validDebugDistance); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment