Пример #1
0
    // Update is called once per frame
    void Update()
    {
        Vector3 myPosition = Camera.main.WorldToViewportPoint(transform.position);

        // If an object containing this script goes off left-screen, destroy it immediately
        if (myPosition.x < 0)
        {
            if (gameObject.name.Substring(0, 5) == "Enemy")
            {
                spawningScript.cullEnemy();
            }

            Destroy(gameObject);
        }
    }
Пример #2
0
    void OnTriggerEnter2D(Collider2D other)
    {
        // Bullets destroy enemies, but they don't destroy enemy A, which is a projectile
        if (other.gameObject.name.Substring(0, 5) == "Enemy")
        {
            Destroy(other.gameObject);

            if (other.gameObject.name[6] != 'A' && other.gameObject.tag != "Invunrable")
            {
                spawning.enemyHit();
            }
            else
            {
                spawning.cullEnemy();
            }
        }
    }