Skip to content

Instantly share code, notes, and snippets.

@pr00thmatic
Created November 28, 2021 00:38
Show Gist options
  • Save pr00thmatic/d76a8b792f78cce418c4cb424f35b055 to your computer and use it in GitHub Desktop.
Save pr00thmatic/d76a8b792f78cce418c4cb424f35b055 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ArrowPorter : MonoBehaviour {
public static ArrowPorter selected;
[Header("Initialization")]
public Arrow arrowPrototype;
public Camera specialCamera;
public Transform spawns;
void Update () {
RaycastHit hit;
Ray ray = (specialCamera? specialCamera: Camera.main).ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit) && hit.collider.GetComponentInParent<ArrowPorter>() == this) {
if (Input.GetMouseButtonDown(1)) {
Arrow created = Instantiate(arrowPrototype);
created.line.SetPosition(0, hit.point + hit.normal * 0.05f);
created.specialCamera = specialCamera;
created.transform.parent = spawns;
}
}
}
void OnMouseEnter () {
selected = this;
}
void OnMouseExit () {
if (selected == this) {
selected = null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment