Beispiel #1
0
    public void DropPiece()
    {
        if (!canDropPiece)
        {
            return;
        }
        GameObject piece = Instantiate(Resources.Load("Prefabs/MainCanvas/DroppedPiece")) as GameObject;

        piece.transform.SetParent(Dial.underLayer, false);
        Vector2 position = new Vector2(rt.anchoredPosition.x, rt.anchoredPosition.y);
        //angle it
        float radians = (-Mathf.PI / 2) + Mathf.Atan2(position.y, position.x);

        piece.transform.eulerAngles = new Vector3(piece.transform.eulerAngles.x, piece.transform.eulerAngles.y, radians * Mathf.Rad2Deg);

        ((RectTransform)piece.transform).anchoredPosition = position;
        Drop dc = piece.GetComponent <Drop> ();

        dc.SetTypes(srcFileName);

        System.Random r   = new System.Random();
        float         rng = (float)r.NextDouble() * 100; //random float between 0 and 100
        //note: threshold values are exclusive, which means if timesShot is equal to it, it's considered outside the rarity threshold
        bool outsideThreshold = (rarityUpWithHits && timesShot <= rareDropThreshold) ||
                                (!rarityUpWithHits && timesShot >= rareDropThreshold);

        if (outsideThreshold)
        {
            if (rng <= normalChance)
            {
                dc.MakeRare();
            }
        }
        else
        {
            if (rng <= rareChance)
            {
                dc.MakeRare();
            }
        }

        //this chance happens regardless of other factors like lane and times shot
        if (rng <= omnitechChance)
        {
            dc.MakeOmnitech();
        }

        //piece.GetComponent<Drop> ().MakeRare ();

        GameEvent ge = new GameEvent("piece_dropped");          //in case other systems need to know about drop events

        //add relevant arguments
        ge.addArgument(position);
    }