Beispiel #1
0
    void Start()
    {
        WorldAudioPool.Init();

        RetrieveTargetsCount();

#if UNITY_EDITOR
        //in the editor we find which level we are currently in. Inefficient but since any level can be opened in the
        //editor we can't assume where we start

        string currentScene = SceneManager.GetActiveScene().path;
        for (int i = 0; i < GameDatabase.Instance.episodes.Length && s_CurrentEpisode < 0; ++i)
        {
            for (int j = 0; j < GameDatabase.Instance.episodes[i].scenes.Length; ++j)
            {
                if (GameDatabase.Instance.episodes[i].scenes[j] == currentScene)
                {
                    s_CurrentEpisode = i;
                    s_CurrentLevel   = j;
                    break;
                }
            }
        }
#else
        //in the final game, we init everything to episode & level 0, as we can't start from somewhere else
        if (s_CurrentEpisode < 0 || s_CurrentLevel < 0)
        {
            s_CurrentEpisode = 0;
            s_CurrentLevel   = 0;
        }
#endif

        GameSystemInfo.Instance.UpdateTimer(0);
    }
    void Destroy()
    {
        Vector3 position = transform.position;

        var effect = PoolSystem.Instance.GetInstance <GameObject>(PrefabOnDestruction);

        effect.transform.position = position;
        effect.SetActive(true);

        int count = Physics.OverlapSphereNonAlloc(position, ReachRadius, s_SphereCastPool, 1 << 10);

        for (int i = 0; i < count; ++i)
        {
            Target t = s_SphereCastPool[i].GetComponent <Target>();

            t.Got(damage);
        }

        gameObject.SetActive(false);
        m_Rigidbody.velocity        = Vector3.zero;
        m_Rigidbody.angularVelocity = Vector3.zero;
        m_Owner.ReturnProjecticle(this);

        var source = WorldAudioPool.GetWorldSFXSource();

        source.transform.position = position;
        source.pitch = Random.Range(0.8f, 1.1f);
        source.PlayOneShot(DestroyedSound);
    }
Beispiel #3
0
    public void GetHit(float damage)
    {
        m_CurrentHealth -= damage;
        healthBar.value  = m_CurrentHealth;

        if (HitPlayer != null)
        {
            HitPlayer.PlayRandom();
        }

        if (m_CurrentHealth > 0)
        {
            gameObject.SendMessage("GetsProvoked");
            return;
        }

        Vector3 position = transform.position;

        //the audiosource of the target will get destroyed, so we need to grab a world one and play the clip through it
        if (HitPlayer != null)
        {
            var source = WorldAudioPool.GetWorldSFXSource();
            source.transform.position = position;
            source.pitch = HitPlayer.source.pitch;
            source.PlayOneShot(HitPlayer.GetRandomClip());
        }

        if (DestroyedEffect != null)
        {
            var effect = PoolSystem.Instance.GetInstance <ParticleSystem>(DestroyedEffect);
            effect.time = 0.0f;
            effect.Play();
            effect.transform.position = position;
        }

        m_Destroyed = true;

        gameObject.SetActive(false);

        GameSystem.Instance.TargetDestroyed(pointValue);
    }
Beispiel #4
0
    public void PlayImpact(Vector3 position, Vector3 normal, Material material = null)
    {
        ImpactSetting setting = null;

        if (material == null || !m_SettingLookup.TryGetValue(material, out setting))
        {
            setting = DefaultSettings;
        }

        var sys = PoolSystem.Instance.GetInstance <ParticleSystem>(setting.ParticlePrefab);

        sys.gameObject.transform.position = position;
        sys.gameObject.transform.forward  = normal;

        sys.gameObject.SetActive(true);
        sys.Play();

        var source = WorldAudioPool.GetWorldSFXSource();

        source.transform.position = position;
        source.pitch = Random.Range(0.8f, 1.1f);
        source.PlayOneShot(setting.ImpactSound);
    }
Beispiel #5
0
 void Start()
 {
     WorldAudioPool.Init();
     GameSystemInfo.Instance.UpdateScore(0);
     StartTimer();
 }
 void Awake()
 {
     s_Instance = this;
 }