Exemplo n.º 1
0
 public void restorePlayerProps()
 {
     dying = false;
     // set back original shader
     setBackOrigShader();
     // set back player's original layer
     GameObjectTools.setLayerForShapes(gameObject, layersCP);
 }
Exemplo n.º 2
0
    public void startAnimation()
    {
#if UNITY_EDITOR
        wasDying = true;
#endif
        dying = true;

        // change CP shape's current layer so it doesn't collide with any other shape
        layersCP = gameObject.GetComponent <ChipmunkShape>().layers;
        GameObjectTools.setLayerForShapes(gameObject, 0);

        // set special shader which will render this game object in front of all layers
        animComp = GetComponentInChildren <AnimateTiledTexture>();
        animComp.GetComponent <Renderer>().sharedMaterial.shader = shaderForDie;

        // execute a little jump as dying animation
        GetComponent <ChipmunkShape>().body.velocity = Vector2.zero;
        jump.forceJump(GetComponent <Player>().lightJumpVelocity);
    }
Exemplo n.º 3
0
    public void Start()
    {
        // start from current game object's layer (the one seen in Inspector)
        uint currentMask = (uint)(1 << gameObject.layer);

        // adds to current mask all the other additional layers added by the user
        for (int i = 0; i < otherLayersBelongTo.Length; ++i)
        {
            currentMask |= (uint)(1 << otherLayersBelongTo[i]);
        }

        // generate a collision mask, as per Chipmunk's layers definition, for game object's current mask
        uint mask = 0;

        //what is the max valid layer slot you defined on Unity's Layers window
        int unityLayersCount = CountLayers.countUnitysLayers();

        /// For every layer this game object belongs: ask what other layer/s it collides with.
        /// When it collides then set the correct bit mask
        for (int i = 0; i < unityLayersCount; ++i)
        {
            // if bit i isn't 1 then continue
            if (((currentMask >> i) & 1) != 1)
            {
                continue;
            }
            for (int j = 0; j < unityLayersCount; ++j)
            {
                /// NOTES:
                /// - first 8 layers are built-in layers.
                /// - built-in layers without name aren't ignored with every other built-in layers, hence you will see them as 1 in the matrix
                if (!Physics.GetIgnoreLayerCollision(i, j))
                {
                    mask |= (uint)(1 << j);
                }
            }
        }

        // Chipmunk use ~(uint)0 as mask to hit with all shapes

        GameObjectTools.setLayerForShapes(gameObject, mask);
    }