forked from kookmin-sw/cap-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using UnityEngine; | ||
using System.Threading.Tasks; | ||
|
||
public class ProjectileHandler : MonoBehaviour | ||
{ | ||
private Rigidbody2D rb; | ||
private float angle; // 이동에 따른 회전각 | ||
public bool isDoubleShot = false; // 더블샷 여부 | ||
|
||
public float massPower; // 질량에 대한 파워 | ||
|
||
private void Awake() | ||
{ | ||
rb = GetComponent<Rigidbody2D>(); | ||
|
||
rb.mass = InGameManager.IT.projectileMass; // 1.5f: 화살, 3.5f: 미사일 | ||
massPower = rb.mass; | ||
} | ||
|
||
public void Set(float speed, Vector3 position, int direction, bool isDoubleShot) | ||
{ | ||
this.isDoubleShot = isDoubleShot; // 더블샷 여부 설정 | ||
|
||
// 방향 체크 | ||
// position.x *= direction; | ||
|
||
// Debug.Log("set proj x: " + position.x + ", dir: " + direction); | ||
|
||
rb.AddForce(position * speed * massPower, ForceMode2D.Impulse); // 발사 | ||
|
||
DeleteTimer(5); | ||
} | ||
|
||
private void FixedUpdate() | ||
{ | ||
angle = Mathf.Atan2(rb.velocity.y, rb.velocity.x) * Mathf.Rad2Deg; // 이동에 따른 회전각 계산 | ||
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); // 회전 | ||
|
||
var windPower = InGameManager.IT.windPower; | ||
var windPowerCoefficient = InGameManager.IT.windPowerCoefficient; // 바람 세기 계수 | ||
rb.AddForce(new Vector3(windPower * windPowerCoefficient,0,0), ForceMode2D.Force); // 바람 재적용 // AI 명중률 감소 | ||
} | ||
|
||
private void OnDestroy() | ||
{ | ||
// 더블샷이 아니면 타이머 시작 | ||
if (isDoubleShot) | ||
return; | ||
|
||
InGameManager.IT.StartTimer(); // 타이머 시작 | ||
InGameManager.IT.CleanLine(); // 예상각도 UI 제거 | ||
} | ||
|
||
private async void DeleteTimer(float sec) | ||
{ | ||
int t = (int)(sec * 1000); | ||
await Task.Delay(t); | ||
|
||
if (this) | ||
Destroy(gameObject); | ||
} | ||
} |