Exemple #1
0
    void Shoot()
    {
        float temp_ao = STATS.accuracyOffset * UTIL.FastDist(transform.position, UTIL.MousePos(), 0.1f);

        Vector3      targetPos = UTIL.MousePos() + new Vector3(Random.Range(-temp_ao, temp_ao), Random.Range(-temp_ao, temp_ao));
        Vector3      fireDir   = targetPos - transform.position;
        RaycastHit2D shot      = Physics2D.Raycast(STATS.bulletSpawnPoint.position, fireDir, STATS.distance, STATS.hitLayers);

        if (shot.collider != null)
        {
            //Debug.Log("hit");
            if (shot.collider.gameObject.GetComponent <PlayerStats>() != null)
            {
                shot.collider.gameObject.GetComponent <PlayerStats>().TakeDamage(STATS.damage);
            }
            if (shot.collider.gameObject.CompareTag("Breakable"))
            {
                shot.collider.gameObject.GetComponent <ObjectStats>().TakeDamage(STATS.damage);
            }
            //Debug.Log("hit");
            LineRenderer lr = Instantiate(STATS.bulletLR, STATS.bulletSpawnPoint.position, Quaternion.identity).GetComponent <LineRenderer>();
            lr.SetPosition(0, STATS.bulletSpawnPoint.transform.position);
            lr.SetPosition(1, shot.point);

            Instantiate(STATS.muzzleFlash, STATS.barrelEnd.position, UTIL.GetPlayer().transform.rotation);

            STATS.fireRate_timer   = STATS.fireRate;
            STATS.magSize_counter -= 1;
        }
    }
Exemple #2
0
 // Update is called once per frame
 void Update()
 {
     if ((doorPos != null) && (UTIL.FastDist(UTIL.GetPlayer().transform.position, doorPos.position, 0.1f) <= accessDistance) && Input.GetKeyDown(KeyCode.E))
     {
         anim.SetBool("open", !open);
         open = !open;
     }
 }
Exemple #3
0
    // Update is called once per frame
    void Update()   //----매 프레임마다 한번씩 실행----
    {
        bool inSight = false;

        /*
         * bool 타입 변수 inSight
         * inSight = false: 시야에 안보임, inSight = true: 보임
         */
        if (!selfRaycast)
        {
            foreach (Transform pos in raycastPos)   //raycastPos라는 리스트 안에 있는 모든 Transform 타입 변수(pos)에 대해
            {
                RaycastHit2D cast = Physics2D.Raycast(pos.position, target.position - pos.position, UTIL.FastDist(target.position, pos.position, 0.05f), wallLayers);

                /*
                 * RaycastHit2D 타입 변수 cast
                 * pos의 위치에서 Transform 타입 변수 target(플레이어)의 방향으로 target(플레이어) 까지의 거리만큼
                 * 레이저를 wallLayers(벽 레이어)에서 발사
                 */
                if ((cast.collider == null && UTIL.FastDist(target.position, pos.position, 0.05f) <= maxDist) || UTIL.FastDist(target.position, pos.position, 0.05f) <= showDist)
                {
                    inSight = true;
                }

                /*
                 * 만약 레이저에 아무것도 닿지 안았고 발사 지점과 너무 멀지 않았다면:
                 * inSight를 참으로 설정한다 => 보이는 거임
                 */
            }
        }
        else
        {
            RaycastHit2D cast = Physics2D.Raycast(transform.position, target.position - transform.position, UTIL.FastDist(target.position, transform.position, 0.05f), wallLayers);
            if ((cast.collider == null && UTIL.FastDist(target.position, transform.position, 0.05f) <= maxDist) || UTIL.FastDist(target.position, transform.position, 0.05f) <= showDist)
            {
                inSight = true;
            }
        }



        //-------애니메이션(사라지기/보이기 효과)---------
        if (useAnim)
        {
            if (inSight)
            {
                anim.SetBool("InSight", true);
            }
            else
            {
                anim.SetBool("InSight", false);
            }
        }
        else
        {
            if (inSight)
            {
                sr.enabled = true;
            }
            else
            {
                sr.enabled = false;
            }
        }
        //Debug.Log("InSight: " + inSight);
    }