Skip to content

Instantly share code, notes, and snippets.

@kazumalab
Last active December 1, 2016 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazumalab/187949f43f66d7b2deb9cff780b425ef to your computer and use it in GitHub Desktop.
Save kazumalab/187949f43f66d7b2deb9cff780b425ef to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PointerTest : MonoBehaviour {
private LineRenderer pointer;
private void Start () {
pointer = this.GetComponent<LineRenderer>();
pointer.numPositions = 2;
}
private void Update () {
pointer.SetPosition (0, this.transform.position);
RaycastHit hit;
if (Physics.Raycast (this.transform.position, this.transform.forward * 10f, out hit, 100)) {
if (hit.collider.tag == "Point") {
pointer.SetPosition (1, hit.point);
EnablePointer ();
} else {
DisEnablePointer ();
}
} else {
DisEnablePointer ();
}
}
private void EnablePointer () {
pointer.enabled = true;
}
private void DisEnablePointer () {
pointer.enabled = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment