private void Update()
    {
        float vjerojatnost = PucanjuSekundi + Time.deltaTime;

        if (Random.value < vjerojatnost)
        {
            Fire();
        }
        void Fire()
        {
            Vector3    offset         = new Vector3(0, = 1.0f, 0);
            Vector3    polozajpucanja = transform.position + offset;
            GameObject missile        = Instantiate(projektil, polozajpucanja, Quaternion.identity) as GameObject;

            missile.GetComponent <Rigidbody2D>().velocity = new Vector2(0, = brzinaProjektila);
        }

        void OnTriggerEnter2D(Collider2D collider)
        {
            Projektil missile = collider.gameObject.GetComponent <Projektil>();

            if (missile)
            {
                missile.Hit();
                snaga -= missile.GetDamage();
                if (snaga <= 0)
                {
                    Destroy(gameObject);
                }
            }
        }
    }
Exemple #2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        Projektil missile = collision.gameObject.GetComponent <Projektil>();

        if (missile)
        {
            snaga -= missile.GetDamage();
            missile.Hit();
            if (snaga <= 0)
            {
                Die();
            }
        }
    }
    private void OnTriggerEnter2D(Collider2D collider)
    {
        Projektil missile = collider.gameObject.GetComponent <Projektil>();

        if (missile)
        {
            missile.Hit();
            snaga -= missile.GetDamage();
            if (snaga <= 0)
            {
                Destroy(gameObject);
            }
        }
    }
    void OnTriggerEnter2D(Collider2D collider)
    {
        Projektil missile = collider.gameObject.GetComponent <Projektil> ();

        if (missile)
        {
            missile.Hit();
            snaga -= missile.GetDamage();
            if (snaga <= 0)
            {
                AudioSource.PlayClipAtPoint(zvukUnistenja, transform.position);
                Destroy(gameObject);
            }
        }
    }