Skip to content

Instantly share code, notes, and snippets.

@tarukosu
Last active December 18, 2017 11:22
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 tarukosu/4294fbf2bce9da19941d8689c2661e5a to your computer and use it in GitHub Desktop.
Save tarukosu/4294fbf2bce9da19941d8689c2661e5a to your computer and use it in GitHub Desktop.
GunScript.cs
using UnityEngine;
public class GunScript : MonoBehaviour {
public ITangoController TangoController;
public GameObject LaserBeam;
bool previousSelectButton = false;
private GameObject muzzle;
...
void Start () {
muzzle = transform.Find("Muzzle").gameObject;
muzzle.transform.localPosition = new Vector3(0f, -0.1f, 0.2f);
muzzle.transform.localRotation = Quaternion.Euler(5f, 0f, 0f);
...
}
...
void Update () {
if(TangoController == null)
{
return;
}
var t = 0.8f;
transform.localPosition = Vector3.Lerp(transform.localPosition, TangoController.transform.position, t);
transform.localRotation = Quaternion.Lerp(transform.localRotation, TangoController.transform.rotation, t);
// ビームの発射
if (previousSelectButton == false && TangoController.SelectButton)
{
var beam = Instantiate(LaserBeam, muzzle.transform.position, muzzle.transform.rotation);
}
previousSelectButton = TangoController.SelectButton;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment