-
Notifications
You must be signed in to change notification settings - Fork 2
develop knife
Seong Hyeok OH edited this page Mar 16, 2023
·
12 revisions
- Boundary(무기가 화면 밖으로 나가면 삭제 경계선)
- GameManager
public int[] killCount = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Whip, MagicWand, Knife, Axe, Cross, KingBible, FireWand, Garlic, SantaWater, Peachone, EbonyWings, Runetracer, LightningRing
- Weapon
private void OnTriggerExit2D(Collider2D col)
{
if (col.gameObject.tag == "Boundary")
{
Destroy(this.gameObject);
}
}
-PlayerMovement
Vector2 preMovement; //이전 이동 방향 벡터 가져오기
void Update(){
...
if (movement != Vector2.zero)
{
preMovement = movement;
}
}
public Vector2 PreMovement { get { return preMovement; } }
- Knife
public class Knife : MonoBehaviour
{
float timer = 0;
bool useKnife = false;
Vector3 knifeTransform;
int touch = 0;
void Update()
{
if (!useKnife) return; //knife 사용 안할 때 Update를 안 함
transform.position += knifeTransform * GameManager.instance.character.GetComponent().Weapons[GameManager.instance.character.GetComponent().TransWeaponIndex[2]].WeaponTotalStats[((int)Enums.WeaponStat.ProjectileSpeed)] * Time.deltaTime;
if(touch == 3) //관통 계수
{
Destroy(this.gameObject);
}
}
//ToDo: totalAttackRange 적용하기
public void FireKnife(GameObject objPre)
{
timer += Time.deltaTime;
if (timer > objPre.GetComponent().WeaponTotalStats[((int)Enums.WeaponStat.Cooldown)])
{
for (int i = 0; i < objPre.GetComponent().WeaponTotalStats[((int)Enums.WeaponStat.Amount)]; i++)
{
GameObject newobs = Instantiate(objPre); //skillFiringSystem에서 프리팹 가져오기
newobs.transform.parent = GameObject.Find("SkillFiringSystem").transform;
newobs.transform.position = GameManager.instance.player.transform.position; //시작 위치
newobs.GetComponent().knifeTransform = setDirection(newobs);
newobs.GetComponent().useKnife = true;
}
timer = 0;
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.gameObject.tag == "Monster")
{
touch++;
}
}
private Vector3 setDirection(GameObject obj) {
//칼날 방향
if (GameManager.instance.player.Movement.x > 0)
{
obj.GetComponent().flipY = true;
if (GameManager.instance.player.Movement.y > 0) { obj.GetComponent().rotation = Quaternion.Euler(0, 0, 135); }
else if (GameManager.instance.player.Movement.y < 0) { obj.GetComponent().rotation = Quaternion.Euler(0, 0, 45); }
else { obj.GetComponent().rotation = Quaternion.Euler(0, 0, 90); }
}
else if (GameManager.instance.player.Movement.x < 0)
{
obj.GetComponent().flipY = false;
if (GameManager.instance.player.Movement.y > 0) { obj.GetComponent().rotation = Quaternion.Euler(0, 0, 45); }
else if (GameManager.instance.player.Movement.y < 0) { obj.GetComponent().rotation = Quaternion.Euler(0, 0, 135); }
else { obj.GetComponent().rotation = Quaternion.Euler(0, 0, 90); }
}
else
{
if (GameManager.instance.player.Movement.y > 0) { obj.GetComponent().rotation = Quaternion.Euler(0, 0, 0); }
else if (GameManager.instance.player.Movement.y < 0) { obj.GetComponent().rotation = Quaternion.Euler(0, 0, 180); }
else { obj.GetComponent().rotation = Quaternion.Euler(GameManager.instance.player.PreMovement); }
}
//이동 방향을 가져옴
if (GameManager.instance.player.PreMovement == Vector2.zero){ obj.GetComponent().flipY = true; return Vector3.right;}
else if (GameManager.instance.player.Movement == Vector2.zero & GameManager.instance.player.PreMovement != Vector2.zero) { return GameManager.instance.player.PreMovement;}
else { return GameManager.instance.player.Movement; }
}