コード例 #1
0
    public void TakeDamage(int damage)
    {
        health -= damage;

        // Modify color alpha
        Color color = spriteRenderer.color;

        color.a -= (float)damage / (float)maxHealth;
        spriteRenderer.color = color;

        if (health == 0)
        {
            Destroy(gameObject);
            spawner.ReplenishAsteroid();
        }
        else if (maxHealth / health >= 2 && !halfLife)
        {
            // If we hit half-health, go half size & spawn another half-size
            HalfLife();

            Asteroid  duplicate = Instantiate(asteroid, transform.position, Quaternion.identity).GetComponent <Asteroid>();
            Direction direction = (Direction)Random.Range(0, 4);
            print(direction);
            duplicate.Initialize(direction);
        }
    }