Skip to content

Instantly share code, notes, and snippets.

@pr00thmatic
Created November 28, 2021 00:39
Show Gist options
  • Save pr00thmatic/c586f590edd1c1f47b35b3bc8771eef0 to your computer and use it in GitHub Desktop.
Save pr00thmatic/c586f590edd1c1f47b35b3bc8771eef0 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Arrow : MonoBehaviour {
[Header("Information")]
public bool isSelected = true;
public float distance = 0;
[Header("Initialization")]
public LineRenderer line;
public GameObject arrowHead;
public Camera specialCamera;
void Update () {
if (isSelected) {
RaycastHit hit;
Ray ray = (specialCamera? specialCamera: Camera.main).ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit)) {
line.SetPosition(1, hit.point + hit.normal * 0.05f);
arrowHead.transform.position = line.GetPosition(1);
arrowHead.transform.forward = line.GetPosition(0) - line.GetPosition(1);
}
if (Input.GetMouseButtonUp(1)) {
isSelected = false;
if (!ArrowPorter.selected) {
Destroy(gameObject);
}
}
} // else {
// RaycastHit hit;
// Ray ray = (specialCamera? specialCamera: Camera.main).ScreenPointToRay(Input.mousePosition);
// if (Physics.Raycast(ray, out hit)) {
// Vector3 direction = line.GetPosition(0);
// Vector3 startingPoint = line.GetPosition(1);
// Ray r = new Ray(startingPoint, direction);
// distance = Vector3.Cross(r.direction, hit.point).magnitude;
// } else {
// distance = Mathf.Infinity;
// }
// }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment