Ejemplo n.º 1
0
    public void DestroyGround(CircleCollider2D cc)
    {
        V2int c = World2Pixel(cc.bounds.center.x, cc.bounds.center.y);
        int   r = Mathf.RoundToInt(cc.bounds.size.x * widthPixel / widthWorld);
        int   px, nx, py, ny;

        for (int i = 0; i <= r; i++)
        {
            int temp = (int)Mathf.RoundToInt(Mathf.Sqrt(r * r - i * i));

            for (int j = 0; j <= temp; j++)
            {
                px = c.x + i;
                nx = c.x - i;
                py = c.y + j;
                ny = c.y - j;

                sr.sprite.texture.SetPixel(px, py, hole);
                sr.sprite.texture.SetPixel(nx, py, hole);
                sr.sprite.texture.SetPixel(px, ny, hole);
                sr.sprite.texture.SetPixel(nx, ny, hole);
            }
        }
        sr.sprite.texture.Apply();
        Destroy(GetComponent <PolygonCollider2D>());
        createCollider.SetCollider();
    }
Ejemplo n.º 2
0
    void Start()
    {
        //reference to CreateLevelCollider script
        createCollider = GetComponent <CreateLevelCollider>();
        //reference to sprite renderer
        sr = GetComponent <SpriteRenderer>();
        //Create clone of the texture, so we won't alter(f**k up) the original
        Texture2D tex_clone = (Texture2D)Instantiate(tex);

        //Create a sprite from the cloned texture and set it as texture in the spriterenderer
        sr.sprite = Sprite.Create(tex_clone, new Rect(0f, 0f, tex.width, tex.height), new Vector2(0.5f, 0.5f));
        //make a transparant colour(Color.clear would also work, but now you kind of make it yourself)
        hole = new Color(0f, 0f, 0f, 0f);
        //Set the properties according to the sizes of the new sprite
        SetDimensions();
        //let the bullet know what the ground is
        HandleExplosion.groundController = this;
        // set collider on gameobject
        createCollider.SetCollider();
    }