Exemple #1
0
    protected void SpawnBullet(Vector3 position, Vector3 destPosition, float velocity)
    {
        Bullet  bullet;
        Vector3 dir = (destPosition - position).normalized;

        if (m_HitScanType == HitScanType.Raycasting)
        {
            bullet = SDObjectPool.GetPool("Bullet").ActiveObject <Bullet>(
                position,
                Quaternion.LookRotation(dir).eulerAngles
                );
        }
        else
        {
            bullet = PhotonNetwork.Instantiate(
                "Bullet",
                position,
                Quaternion.LookRotation(dir),
                0
                ).GetComponent <Bullet>();
        }

        bullet.Initialize(m_HitScanType, m_Damage);

        // 총알에 velocity 추가
        bullet.GetComponent <Rigidbody>().velocity =
            dir * velocity;
    }
    public GameObject Instantiate(string prefabId, Vector3 position, Quaternion rotation)
    {
        Debug.LogWarning("Instantiate Prefab :" + prefabId);
        var p = SDObjectPool.GetPool(prefabId);

        if (p != null)
        {
            return(p.ActiveObject(position, rotation.eulerAngles));
        }
        else
        {
            var go = Resources.Load <GameObject>(prefabId);
            return(go != null?Instantiate(go, position, rotation) : null);
        }
    }
Exemple #3
0
    protected void Fire()
    {
        // 총 발포
        if (Time.time - m_LastFired > 1 / m_FireRate)
        {
            m_LastFired = Time.time;

            m_CurrentAmmo -= 1;

            m_ShootAudioSource.clip = m_SoundClips.shootSound;
            m_ShootAudioSource.Play();

            photonView.RPC("OnFire", PhotonTargets.Others);

            if (!m_isAiming) // 조준중이지 않으면
            {
                m_Animator.Play("Fire", 0, 0f);
            }
            else // 조준시
            {
                m_Animator.Play("Aim Fire", 0, 0f);
            }

            if (!m_RandomMuzzleflash)
            {
                m_MuzzleParticles.Emit(1);
            }
            else
            {
                if (m_EnableSparks)
                {
                    // 랜덤 스파크 파티클 생성
                    m_SparkParticles.Emit(Random.Range(m_MinSparkEmission, m_MaxSparkEmission));
                }
            }

            if (m_EnableMuzzleflash == true)
            {
                m_MuzzleParticles.Emit(1);
                if (m_Co_MuzzleFlash != null)
                {
                    StopCoroutine(m_Co_MuzzleFlash);
                }
                m_Co_MuzzleFlash = StartCoroutine(MuzzleFlashLight());
            }

            var        ray = Camera.main.ScreenPointToRay(new Vector2(Screen.width * 0.5f, Screen.height * 0.5f));
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, m_MaxDistance, m_RaycastLayerMask))
            {
                if (m_HitScanType == HitScanType.Raycasting && hit.collider.transform.tag == "Player")
                {
                    var character = hit.collider.transform.gameObject.GetComponent <Character>();
                    if (!character.photonView.isMine)
                    {
                        character.Damage(m_Damage);
                    }
                }
            }

            Debug.DrawRay(ray.GetPoint(0), ray.direction);

            Vector3 destPos = hit.collider != null ? hit.point : ray.direction * m_MaxDistance;

            if (m_HitScanType == HitScanType.Raycasting)
            {
                photonView.RPC("SpawnBullet", PhotonTargets.All, new object[] { m_Spawnpoints.bulletSpawnPoint.transform.position, destPos, m_BulletForce });
            }
            else
            {
                SpawnBullet(m_Spawnpoints.bulletSpawnPoint.transform.position, destPos, m_BulletForce);
            }

            // 탄피 생성
            SDObjectPool.GetPool("Big_Casing").ActiveObject(m_Spawnpoints.casingSpawnPoint.transform.position, m_Spawnpoints.casingSpawnPoint.transform.rotation.eulerAngles);
        }
    }