예제 #1
0
    private void Update()
    {
        if (Input.GetKeyUp(KeyCode.Mouse0))
        {
            StartCoroutine(ShootEffect());
        }

        if (GameManager.Singleton.GS == GameState.Working)
        {
            if (FireState == FireFlow.Lock)
            {
                FireState = FireFlow.Ready;
            }

            if (Input.GetKey(KeyCode.Mouse0) && FireState == FireFlow.Ready && !isChangeMag)
            {
                Shot();
            }
            Rest();

            ChangeMag();
        }
        else
        {
            //Lock gun trigger
            FireState = FireFlow.Lock;
        }
    }
예제 #2
0
 void Rest()
 {
     if (FireState == FireFlow.Rest)
     {
         timer[0] += Time.deltaTime;
         if (timer[0] >= RepeatTime)
         {
             FireState = FireFlow.Ready;
         }
     }
 }
예제 #3
0
    void Shot()
    {
        if (Player_Data.Singleton.LoadedAmmo > 0)
        {
            LR.enabled = true;

            LR.SetPosition(0, FireSpot.position);

            bool isFine = false;
            rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0f));


            if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out rayHit, weaponRange, layerMask, QueryTriggerInteraction.Ignore))
            {
                FireState = FireFlow.Shot;
                timer[0]  = 0f;

                LR.SetPosition(1, rayOrigin + (fpsCam.transform.forward * rayHit.distance));

                if (rayHit.transform.tag == "Enemy")
                {
                    rayHit.transform.gameObject.GetComponentInParent <Turret_Logic02>().shotAt = true;
                }



                //GameObject temp = Instantiate(Bullet, FireSpot.position, FireSpot.rotation);   // 나중에 오브젝트 풀로 바꿔주자
                //rb = temp.gameObject.GetComponent<Rigidbody>();
                //rb.AddForce(fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, weaponRange)) * BulletSpeed, ForceMode.VelocityChange);



                FireState = FireFlow.Rest;
            }
            else
            {
                FireState = FireFlow.Shot;
                timer[0]  = 0f;
                LR.SetPosition(1, rayOrigin + (fpsCam.transform.forward * weaponRange));
                FireState = FireFlow.Rest;
            }

            foreach (AudioClip ac in adClips)
            {
                if ("GunFire" == ac.name)
                {
                    isFine        = true;
                    adSour.clip   = ac;
                    adSour.volume = 0.75f;
                    if (Time.time >= timech)
                    {
                        timech = Time.time + RepeatTime;
                        adSour.Play();
                        Player_Data.Singleton.LoadedAmmo--;
                    }
                }
            }



            if (!isFine)
            {
                print("GunFire 파일의 재생을 실패하였습니다." + "코드의 위치는 Gun_Mecanim.cs >>> void Shot() 입니다.");
            }
        }
        else
        {
            foreach (AudioClip ac in adClips)
            {
                if ("GunEmpty" == ac.name)
                {
                    adSour.clip   = ac;
                    adSour.volume = 0.75f;
                    if (!adSour.isPlaying)
                    {
                        adSour.Play();
                    }
                }
            }
            print("Loaded Magazine is empty");
        }
    }