Skip to content

Instantly share code, notes, and snippets.

@chiepomme
Created August 14, 2017 07:36
Show Gist options
  • Save chiepomme/5e468ea1d4e3dfb0dea53b80d59a2f37 to your computer and use it in GitHub Desktop.
Save chiepomme/5e468ea1d4e3dfb0dea53b80d59a2f37 to your computer and use it in GitHub Desktop.
using SmfNoteTiming;
using System;
using UnityEngine;
namespace Idol
{
public class NoteStar : MonoBehaviour
{
[SerializeField]
public float seconds;
[SerializeField]
public int id;
public event Action<int, bool, bool> Judged;
public void SetNote(int id, NoteTiming note)
{
this.id = id;
seconds = note.Seconds;
}
void Awake()
{
transform.localPosition = Vector3.forward * 10f;
}
public void UpdateTime(float t)
{
transform.localPosition = Vector3.Lerp(Vector3.forward * 10f, Vector3.zero, t);
}
public void Judge()
{
const float judgeDistance = 0.3f;
var success = false;
var isLeft = false;
var leftDist = CameraRig.Current.left.transform.position - transform.position;
var rightDist = CameraRig.Current.right.transform.position - transform.position;
isLeft = leftDist.sqrMagnitude < rightDist.sqrMagnitude;
success = Mathf.Min(leftDist.sqrMagnitude, rightDist.sqrMagnitude) < judgeDistance * judgeDistance;
if (Judged != null) Judged(id, success, isLeft);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment