Created
November 28, 2021 00:38
-
-
Save pr00thmatic/d76a8b792f78cce418c4cb424f35b055 to your computer and use it in GitHub Desktop.
This file contains hidden or 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; | |
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