Skip to content

develop knife

Seong Hyeok OH edited this page Mar 22, 2023 · 12 revisions

준비

  • Boundary(무기가 화면 밖으로 나가면 삭제 경계선)
  • image

단검

  • image
  • image
  • image

진화 단검

  • image
  • image
  • image

스크립트

  • 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);
        }
    }

-EqupitmentData


...
  public static int[] EvoWeaponNeedAccIndex;   //Spinach,Armor,HollowHeart,Pummarola,EmptyTome,Candelabrador,Bracer,Spellbinder,Duplicator,Wings,Attractorb,Clover,Crown,StoneMask,Tiragisu,Skull,SilverRing,GoldRing,MetaglioLeft,MetaglioRight,TorronaBox
    public static int[] EvoAccNeedWeaponIndex;    //Whip,MagicWand,Knife,Axe,Cross,KingBible,FireWand,Garlic,SantaWater,Peachone,EbonyWings,Runetracer,LightningRing
...
    public static void EvolutionPairData()
    {
        // 짝이 없는 무기, 악세서리의 경우는 -1로 초기화
        EvoWeaponNeedAccIndex = new int[13] {2,4,6,5,11,7,0,3,10,-1,-1,1,8};
        EvoAccNeedWeaponIndex = new int[21] { 6, 11, 0, 7, 1, 3, 2, 5, 12, -1, 8, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
    }
...

-Weapon


    private bool mEvolution = false;
...
    public bool isEvoluction()
    {
        bool evoluction = IsMaster();
        var characterTrans = GameManager.instance.player.GetComponent().TransAccessoryIndex;
        if (evoluction && (this.WeaponIndex == characterTrans[EquipmentData.EvoAccNeedWeaponIndex[this.WeaponIndex]]))
        {
            mEvolution = true;
            return mEvolution;
        }
        else { return mEvolution; }
    }
...

-SkillfiringSystrem


...
            case 2:     // Knife
                if (!weapon.isEvoluction()) {
                    GameManager.instance.player.GetComponent().Weapons[GameManager.instance.player.GetComponent().TransWeaponIndex[2]].GetComponent().FireKnife(weaponPrefabs[2]);
                }
                else {
                    GameManager.instance.player.GetComponent().Weapons[GameManager.instance.player.GetComponent().TransWeaponIndex[2]].GetComponent().FireKnife(evolutionWeaponPrefabs[2]);
                }
...

-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;
    int touch = 0;
    int touchLimit;
    void Update()
    {
        if (!useKnife) return;  //knife 사용 안할 때 Update를 안 함
        if(touchLimit <= touch)
        {
            Destroy(this.gameObject);
        }
    }
    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, GameObject.Find("SkillFiringSystem").transform);   //skillFiringSystem에서 프리팹 가져오기
                Vector3 spawnPosition = GameManager.instance.player.transform.position;
                if (i > 1) //여러 개 동시 발사 시 시작 위치를 다르게 설정
                {
                    spawnPosition.y -= ((int)objPre.GetComponent().WeaponTotalStats[((int)Enums.WeaponStat.Area)] * (i-1)) / 2;
                    spawnPosition.y += i * (int)objPre.GetComponent().WeaponTotalStats[((int)Enums.WeaponStat.Area)];
                }
                newobs.transform.position = spawnPosition; //시작 위치
                newobs.GetComponent().useKnife = true;
                newobs.GetComponent().touchLimit = (int)objPre.GetComponent().WeaponTotalStats[(int)Enums.WeaponStat.Piercing];
                Rigidbody2D rb = newobs.GetComponent();
                rb.velocity = setDirection(newobs) * newobs.GetComponent().WeaponTotalStats[(int)Enums.WeaponStat.ProjectileSpeed];
            }
            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.FromToRotation(Vector3.up, 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; }
    }
}

참고 자료

Clone this wiki locally