// Update is called once per frame
    void Update()
    {
        //선택되었는가 아니면 아웃라인 해제
        if (TradeCupcakeTowers.getSelectTower() != this)
        {
            outlineActive(false);
        }


        if (shotTime >= reloadTime)
        {
            //발사 시간 체크
            shotTime = 0;
            //콜라이더 범위 안에 오브젝트가 있는지 체크
            Collider2D[] hitColliders = Physics2D.OverlapCircleAll(transform.position, rangeRadius);

            //하나 이상의 오브젝트가 감지됐는지 체크
            if (hitColliders.Length != 0)
            {
                //가장 가까운 곳에 있는 적을 판별
                float min   = int.MaxValue;
                int   index = -1;
                for (int i = 0; i < hitColliders.Length; i++)
                {
                    if (hitColliders[i].tag == "Enemy")
                    {
                        if (hitColliders[i].GetComponentInParent <PandaController>().health < 0)
                        {
                            continue;
                        }
                        float distance = Vector2.Distance(hitColliders[i].transform.position, transform.position);
                        if (distance < min)
                        {
                            index = i;
                            min   = distance;
                        }
                    }
                }

                if (index == -1)
                {
                    return;
                }

                //타깃으로 방향 설정
                Transform target    = hitColliders[index].transform;
                Vector2   direction = (target.position - transform.position).normalized;

                //발사체 생성
                GameObject projectile = GameObject.Instantiate(projectilePrefab, transform.position, Quaternion.identity) as GameObject;
                projectile.GetComponent <ProjectileScript>().direction = direction;
            }
        }
        shotTime += Time.deltaTime;
    }
Beispiel #2
0
 void Update()
 {
     if (TradeCupcakeTowers.getSelectTower() == null)
     {
         foreach (Text text in textInfo)
         {
             text.enabled = false;
         }
         return;
     }
     else
     {
         foreach (Text text in textInfo)
         {
             text.enabled = true;
         }
     }
 }
Beispiel #3
0
    public static void UpdateInfo()
    {
        CupcakeTower     tower      = TradeCupcakeTowers.getSelectTower();
        ProjectileScript projectile = tower.projectilePrefab.GetComponent <ProjectileScript>();

        foreach (Text text in textInfo)
        {
            switch (text.name)
            {
            case "Atk":
                text.text = projectile.damage.ToString();
                break;

            case "Dps":
                text.text = (projectile.damage * 1 / tower.reloadTime).ToString();
                break;

            case "UpgradeCost":
                text.text = tower.upgradingCost.ToString();
                break;
            }
        }
    }