2022-07-25 02:04:55 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using NaughtyBezierCurves;
|
|
|
|
using HeavenStudio.Util;
|
|
|
|
|
|
|
|
|
|
|
|
namespace HeavenStudio.Games.Scripts_AirRally
|
|
|
|
{
|
2023-01-30 21:42:19 +00:00
|
|
|
public class Shuttlecock : MonoBehaviour
|
2022-07-25 02:04:55 +00:00
|
|
|
{
|
2023-01-30 21:42:19 +00:00
|
|
|
[SerializeField] Transform PlayerTarget;
|
|
|
|
[SerializeField] Transform OtherTarget;
|
|
|
|
[SerializeField] float TargetHeight;
|
|
|
|
[SerializeField] float TargetHeightLong;
|
|
|
|
|
2022-07-25 02:04:55 +00:00
|
|
|
public float startBeat;
|
2023-01-30 21:42:19 +00:00
|
|
|
public float flyBeats;
|
2022-07-25 02:04:55 +00:00
|
|
|
|
|
|
|
public bool flyType;
|
|
|
|
bool miss = false;
|
|
|
|
public float flyPos;
|
|
|
|
public bool isReturning;
|
|
|
|
AirRally game;
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
game = AirRally.instance;
|
|
|
|
}
|
2023-01-30 21:42:19 +00:00
|
|
|
|
2022-07-25 02:04:55 +00:00
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
var cond = Conductor.instance;
|
2023-01-30 21:42:19 +00:00
|
|
|
|
|
|
|
Vector3 lastPos = transform.position;
|
|
|
|
if (!GetComponent<Rigidbody2D>().simulated)
|
2022-07-25 02:04:55 +00:00
|
|
|
{
|
2023-01-30 21:42:19 +00:00
|
|
|
float flyPos = cond.GetPositionFromBeat(startBeat, flyBeats);
|
2022-07-27 09:04:02 +00:00
|
|
|
|
2023-01-30 21:42:19 +00:00
|
|
|
Vector3 startPos = isReturning ? PlayerTarget.position : OtherTarget.position;
|
|
|
|
Vector3 endPos = isReturning ? OtherTarget.position : PlayerTarget.position;
|
2022-07-25 02:04:55 +00:00
|
|
|
|
2023-01-30 21:42:19 +00:00
|
|
|
transform.position = Vector3.LerpUnclamped(startPos, endPos, flyPos);
|
2022-07-25 02:04:55 +00:00
|
|
|
|
2023-01-30 21:42:19 +00:00
|
|
|
float yMul = flyPos * 2f - 1f;
|
|
|
|
float yWeight = -(yMul*yMul) + 1f;
|
|
|
|
transform.position += Vector3.up * yWeight * (flyType ? TargetHeightLong : TargetHeight);
|
2022-07-25 02:04:55 +00:00
|
|
|
}
|
2023-01-30 21:42:19 +00:00
|
|
|
|
|
|
|
Vector3 direction = (transform.position - lastPos).normalized;
|
|
|
|
float rotation = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
|
|
|
|
this.transform.eulerAngles = new Vector3(0, 0, rotation - 90f);
|
|
|
|
|
|
|
|
if (miss && flyPos > 2f)
|
2022-07-25 02:04:55 +00:00
|
|
|
{
|
2023-01-30 21:42:19 +00:00
|
|
|
if (cond.GetPositionFromBeat(startBeat, flyBeats + 1f) >= 1f)
|
2022-07-25 02:04:55 +00:00
|
|
|
{
|
|
|
|
GameObject.Destroy(gameObject);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-30 21:42:19 +00:00
|
|
|
|
|
|
|
public void DoNearMiss()
|
|
|
|
{
|
|
|
|
miss = true;
|
|
|
|
Jukebox.PlayOneShot("miss");
|
|
|
|
Rigidbody2D rb = GetComponent<Rigidbody2D>();
|
|
|
|
rb.simulated = true;
|
|
|
|
rb.WakeUp();
|
|
|
|
rb.velocity = Vector3.zero;
|
|
|
|
rb.gravityScale = 10f;
|
|
|
|
rb.AddForce(Vector2.up * 10, ForceMode2D.Impulse);
|
|
|
|
rb.AddForce(Vector2.right * -10, ForceMode2D.Impulse);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void DoThrough()
|
|
|
|
{
|
|
|
|
miss = true;
|
|
|
|
}
|
2022-07-25 02:04:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|