Пример #1
0
    /*
     * void CastRayToWorldAndroidFlick(Vector3 touchPos1,Vector3 touchPos2,float elapsed){
     *      //k so now I'm going to do the whole flick thing for android.
     *
     *      //step1 need to make sure that touchPos1--which is in screen coords gets to hit our object
     *      Ray r = Camera.main.ScreenPointToRay(touchPos1);
     *      RaycastHit test;
     *      LayerMask lm; //our layermask for raycasting to ignore coins not in turn
     *      if (turn == 1) {//so p1's turn want to mask out p2 coins. so mask out layer p2
     *              lm = lm2;//so lm2 is only layer p2. Then at end invert this.
     *      } else {
     *              lm = lm1;
     *      }
     *      lm = ~lm;
     *      if (Physics.Raycast (r.origin, r.direction, out test, Mathf.Infinity, lm)) {
     *
     *              GameObject target = test.collider.gameObject;
     *              Debug.Log(target.name);
     *
     *              coinAndroidTest info = target.GetComponent<coinAndroidTest>();
     *              //if (info.owner != turn){return;} // so exit if WAIT NO use raycast layber bitmask and here just check for locked/set it if false to true and increment a var to decide if turn over
     *
     *              if(info.locked){//so this coin is locked meaning have already launched it
     *                      return;
     *              }
     *              info.locked = true; //so we're going to launch this so need to lock it so can't double launch in same turn
     *      }
     *
     * }*/

    void CastRayToWorldAndroid(Vector3 touchPos1, Vector3 touchPos2, float elapsed)
    {
        /*
         * Vector3 dir = touchPos2 - touchPos1;
         * float dist = dir.magnitude;
         * //Debug.Log(dist + " " + elapsed); most excellent*/
        Vector3    p1 = Vector3.zero;
        Vector3    p2 = Vector3.zero;
        Ray        r1 = Camera.main.ScreenPointToRay(touchPos1);
        Ray        r2 = Camera.main.ScreenPointToRay(touchPos2);
        RaycastHit test1;
        RaycastHit test2;
        LayerMask  lm;        //our layermask for raycasting to ignore coins not in turn

        if (turn == 1)        //so p1's turn want to mask out p2 coins. so mask out layer p2
        {
            lm = lm2;         //so lm2 is only layer p2. Then at end invert this.
        }
        else
        {
            lm = lm1;
        }
        lm = ~lm;
        if (Physics.Raycast(r1.origin, r1.direction, out test1, Mathf.Infinity, lm))
        {
            //so need to check if hit a coin. else lower p.y else raise p.y (because if it's a coin then we're going to miss it if we incrase the ray's height..

            /*namely we know from that default unity cylinder primitive = 2 units high
             * this means due to .1 scale our coins are .2 units high so .2/2 = .1, the half height of interest.
             */
            p1 = test1.point;
            GameObject gotHit = test1.collider.gameObject;
            //Vector3 adjust = gotHit.transform.up;//so the normal of the surface that was hit
            //so need to make adjust to be terrain normal now..



            if (!gotHit.name.StartsWith("Terrain"))
            {
                //p.y -= .1f;//
                //Vector3 adjust = gotHit.transform.up; //try something else b/c when coin upside down, we get 0 -1 0 rather than 0 1 0.
                Vector3 adjust = test1.normal;
                adjust.Normalize();


                //Debug.Log ("p prev: " + p);
                p1 += -.1f * adjust;               //AHA! So that's why. Adjust is being negative b/c coin is flipped over.
                //Debug.Log(adjust);
                //Debug.Log ("p adjusted: " + p + " and adjustment used: " + adjust);
                //Debug.Log("On a coin");
            }
            else                //so need the Terrain normal - credit to Eric on unity forumns
                                //p.y += .1f;
            {
                Terrain t      = gotHit.GetComponent <Terrain>();
                Vector3 relPos = p1 - t.transform.position;
                Vector2 nPos   = new Vector2(Mathf.InverseLerp(0.0f, t.terrainData.size.x, relPos.x), Mathf.InverseLerp(0.0f, t.terrainData.size.z, relPos.z));

                Vector3 adjust = t.terrainData.GetInterpolatedNormal(nPos.x, nPos.y);

                //adjust = adjust.normalized;
                adjust.Normalize();

                p1 += .1f * adjust;
                //Debug.Log("On the floor");
                //Debug.Log(adjust);
                //Debug.Log(gotHit.transform.up); aha, so transform.up gives the normal. need to use this for adjustment so that will work also on inclined surfaces,not just flat ones w/ normal of 0 1 0
            }
        }

        if (Physics.Raycast(r2.origin, r2.direction, out test2, Mathf.Infinity, lm))
        {
            //so need to check if hit a coin. else lower p.y else raise p.y (because if it's a coin then we're going to miss it if we incrase the ray's height..

            /*namely we know from that default unity cylinder primitive = 2 units high
             * this means due to .1 scale our coins are .2 units high so .2/2 = .1, the half height of interest.
             */
            p2 = test2.point;
            GameObject gotHit = test2.collider.gameObject;
            //Vector3 adjust = gotHit.transform.up;//so the normal of the surface that was hit
            //so need to make adjust to be terrain normal now..



            if (!gotHit.name.StartsWith("Terrain"))
            {
                //p.y -= .1f;//
                //Vector3 adjust = gotHit.transform.up; //try something else b/c when coin upside down, we get 0 -1 0 rather than 0 1 0.
                Vector3 adjust = test2.normal;
                adjust.Normalize();


                //Debug.Log ("p prev: " + p);
                p2 += -.1f * adjust;               //AHA! So that's why. Adjust is being negative b/c coin is flipped over.
                //Debug.Log(adjust);
                //Debug.Log ("p adjusted: " + p + " and adjustment used: " + adjust);
                //Debug.Log("On a coin");
            }
            else                //so need the Terrain normal - credit to Eric on unity forumns
                                //p.y += .1f;
            {
                Terrain t      = gotHit.GetComponent <Terrain>();
                Vector3 relPos = p2 - t.transform.position;
                Vector2 nPos   = new Vector2(Mathf.InverseLerp(0.0f, t.terrainData.size.x, relPos.x), Mathf.InverseLerp(0.0f, t.terrainData.size.z, relPos.z));

                Vector3 adjust = t.terrainData.GetInterpolatedNormal(nPos.x, nPos.y);

                //adjust = adjust.normalized;
                adjust.Normalize();

                p2 += .1f * adjust;
                //Debug.Log("On the floor");
                //Debug.Log(adjust);
                //Debug.Log(gotHit.transform.up); aha, so transform.up gives the normal. need to use this for adjustment so that will work also on inclined surfaces,not just flat ones w/ normal of 0 1 0
            }
        }

        //s

        Vector3 dir = p2 - p1;

        Debug.DrawRay(p1, dir, Color.blue, 5.0f);
        RaycastHit hit;
        float      dist = dir.magnitude;

        if (Physics.Raycast(p1, dir, out hit, dist, lm))
        {
            GameObject target = hit.collider.gameObject;


            coinAndroidTest info = target.GetComponent <coinAndroidTest>();
            //if (info.owner != turn){return;} // so exit if WAIT NO use raycast layber bitmask and here just check for locked/set it if false to true and increment a var to decide if turn over

            if (info.locked)            //so this coin is locked meaning have already launched it
            {
                return;
            }
            info.locked = true;             //so we're going to launch this so need to lock it so can't double launch in same turn


            Rigidbody coin = target.GetComponent <Rigidbody>();

            float distToHit = Vector3.Distance(hit.point, clickPos);

            float ratio = distToHit / dist;



            Vector3 offset = hit.point - coin.position;

            float offsetsize = offset.magnitude;
            //Debug.Log(offsetsize); offset = useless for coins--always = .5. For pencilwars (original) it had meaning...
            //Debug.Log(forceFactor);
            forceFactor = target.GetComponent <coinAndroidTest>().forceFactor;

            //so now to try out flicking replace below line with something that takes into account elapsed time and magnitude/that is a measure of velocity of finger
            //Vector3 forceToAdd = dir.normalized * ratio * forceFactor;// * Mathf.Pow (offsetsize,spower);
            float ratio1 = 0.0f;

            Vector3 dirScreen  = touchPos2 - touchPos1;
            float   distScreen = dirScreen.magnitude;
            float   velScreen  = distScreen / elapsed;

            Debug.Log(velScreen);

            /*so now just need to use velScreen to compute ratio1-testing method I'll emply is as follows:
             * 1) Try out a bunch of velScreens-seen printed out and settle on a max one
             * 2)set ratio1 = it/max
             * 3)profit
             * */
            ratio1 = velScreen / maxSpeed;
            Vector3 forceToAdd = dir.normalized * ratio1 * forceFactor;


            coin.AddForceAtPosition(forceToAdd, hit.point);
        }
        //e
    }
Пример #2
0
    void CastRayToWorld(Vector2 pos)
    {
        Ray r = Camera.main.ScreenPointToRay(pos);
        //Vector3 p = r.origin + r.direction*(10 - (-.17f));
        Vector3    p = Vector3.zero;
        RaycastHit test;
        LayerMask  lm;        //our layermask for raycasting to ignore coins not in turn

        if (turn == 1)        //so p1's turn want to mask out p2 coins. so mask out layer p2
        {
            lm = lm2;         //so lm2 is only layer p2. Then at end invert this.
        }
        else
        {
            lm = lm1;
        }
        lm = ~lm;
        //Debug.Log (lm.value);
        //Debug.Log (r.direction);
        if (Physics.Raycast(r.origin, r.direction, out test, Mathf.Infinity, lm))
        {
            //so need to check if hit a coin. else lower p.y else raise p.y (because if it's a coin then we're going to miss it if we incrase the ray's height..

            /*namely we know from that default unity cylinder primitive = 2 units high
             * this means due to .1 scale our coins are .2 units high so .2/2 = .1, the half height of interest.
             */
            p = test.point;
            GameObject gotHit = test.collider.gameObject;
            //Vector3 adjust = gotHit.transform.up;//so the normal of the surface that was hit
            //so need to make adjust to be terrain normal now..



            if (!gotHit.name.StartsWith("Terrain"))
            {
                //p.y -= .1f;//
                //Vector3 adjust = gotHit.transform.up; //try something else b/c when coin upside down, we get 0 -1 0 rather than 0 1 0.
                Vector3 adjust = test.normal;
                adjust.Normalize();


                //Debug.Log ("p prev: " + p);
                p += -.1f * adjust;               //AHA! So that's why. Adjust is being negative b/c coin is flipped over.
                //Debug.Log(adjust);
                //Debug.Log ("p adjusted: " + p + " and adjustment used: " + adjust);
                //Debug.Log("On a coin");
            }
            else                //so need the Terrain normal - credit to Eric on unity forumns
                                //p.y += .1f;
            {
                Terrain t      = gotHit.GetComponent <Terrain>();
                Vector3 relPos = p - t.transform.position;
                Vector2 nPos   = new Vector2(Mathf.InverseLerp(0.0f, t.terrainData.size.x, relPos.x), Mathf.InverseLerp(0.0f, t.terrainData.size.z, relPos.z));

                Vector3 adjust = t.terrainData.GetInterpolatedNormal(nPos.x, nPos.y);

                //adjust = adjust.normalized;
                adjust.Normalize();

                p += .1f * adjust;
                //Debug.Log("On the floor");
                //Debug.Log(adjust);
                //Debug.Log(gotHit.transform.up); aha, so transform.up gives the normal. need to use this for adjustment so that will work also on inclined surfaces,not just flat ones w/ normal of 0 1 0
            }
        }


        if (clicks == 0)
        {
            clickPos = p;
            clicks  += 1;
        }
        else
        {
            clicks = 0;
            Vector3 dir = p - clickPos;

            Debug.DrawRay(clickPos, dir, Color.blue, 5.0f);
            RaycastHit hit;
            float      dist = dir.magnitude;
            if (Physics.Raycast(clickPos, dir, out hit, dist, lm))
            {
                GameObject target = hit.collider.gameObject;


                coinAndroidTest info = target.GetComponent <coinAndroidTest>();
                //if (info.owner != turn){return;} // so exit if WAIT NO use raycast layber bitmask and here just check for locked/set it if false to true and increment a var to decide if turn over

                if (info.locked)                //so this coin is locked meaning have already launched it
                {
                    return;
                }
                info.locked = true;                 //so we're going to launch this so need to lock it so can't double launch in same turn


                Rigidbody coin = target.GetComponent <Rigidbody>();

                float distToHit = Vector3.Distance(hit.point, clickPos);

                float ratio = distToHit / dist;



                Vector3 offset = hit.point - coin.position;

                float offsetsize = offset.magnitude;
                //Debug.Log(offsetsize); offset = useless for coins--always = .5. For pencilwars (original) it had meaning...
                //Debug.Log(forceFactor);
                forceFactor = target.GetComponent <coinAndroidTest>().forceFactor;
                Vector3 forceToAdd = dir.normalized * ratio * forceFactor;                // * Mathf.Pow (offsetsize,spower);

                coin.AddForceAtPosition(forceToAdd, hit.point);
            }
        }
    }
Пример #3
0
    void handleTurn()
    {
        bool canChangeTurn = true;        //so start off saying yes can change turn from px but then go through all of px's coins and if it is the case that at least one remains unlocked, then nope, can't switch

        if (turn == 1)
        {
            foreach (GameObject c in p1coins)
            {
                if (c)
                {
                    coinAndroidTest info = c.GetComponent <coinAndroidTest>();
                    //Debug.Log(info.locked);
                    if (!info.locked)
                    {
                        canChangeTurn = false;
                    }
                }
            }
        }
        else
        {
            foreach (GameObject c in p2coins)
            {
                if (c)
                {
                    coinAndroidTest info = c.GetComponent <coinAndroidTest>();
                    if (!info.locked)
                    {
                        canChangeTurn = false;
                    }
                }
            }
        }

        if (canChangeTurn)
        {
            if (turn == 1)
            {
                foreach (GameObject c in p2coins)
                {
                    if (c)
                    {
                        coinAndroidTest info = c.GetComponent <coinAndroidTest>();
                        info.locked = false;
                    }
                }
                turn = 2;
            }
            else
            {
                foreach (GameObject c in p1coins)
                {
                    if (c)
                    {
                        coinAndroidTest info = c.GetComponent <coinAndroidTest>();
                        info.locked = false;
                    }
                }
                turn = 1;
            }
        }
    }
Пример #4
0
    //to try to merge this coin
    void mergeAid()
    {
        Collider[] stuffHit = Physics.OverlapSphere(transform.position, mergeRadius);
        if (gameObject.tag == "p1")
        {
            if ((cm1.state == 0) || (cm1.state == 1))
            {
                List <int> adjCoinIds = new List <int>();

                foreach (Collider c in stuffHit)
                {
                    GameObject      adjacentCoin = c.gameObject;
                    coinAndroidTest adjCoinInfo  = adjacentCoin.GetComponent <coinAndroidTest>();
                    if ((adjacentCoin.tag == "p1"))
                    {
                        if (!(adjCoinInfo.id == gameObject.GetComponent <coinAndroidTest>().id) && (adjCoinInfo.type == "small"))
                        {
                            if (!(adjCoinInfo.locked))
                            {
                                adjCoinIds.Add(adjCoinInfo.id);
                            }
                        }
                    }
                }

                if (cm1.state == 0)
                {
                    cm1.handleFirst(adjCoinIds, gameObject.GetComponent <coinAndroidTest>().id, transform.position);
                }
                else                    //so state=1, on second coin. Need to first check to make sure that this coin is actually reachable from 1st coin
                {
                    bool terminate = true;
                    foreach (int i in cm1.reachableFromFirstCoin)
                    {
                        if (i == gameObject.GetComponent <coinAndroidTest>().id)
                        {
                            terminate = false;
                        }
                    }
                    if (terminate)
                    {
                        cm1.clearLines();                        //new
                        return;
                    }
                    cm1.handleSecond(adjCoinIds, gameObject.GetComponent <coinAndroidTest>().id, transform.position);
                }
            }
            else                //do the combining!
                                //for now just place on centroid, highest height + the .5, and average the healths of the 3 constituent coins
            {
                cm1.merge();
            }
        }
        else
        {
            if ((cm2.state == 0) || (cm2.state == 1))
            {
                List <int> adjCoinIds = new List <int>();

                foreach (Collider c in stuffHit)
                {
                    GameObject      adjacentCoin = c.gameObject;
                    coinAndroidTest adjCoinInfo  = adjacentCoin.GetComponent <coinAndroidTest>();
                    if ((adjacentCoin.tag == "p2"))
                    {
                        if (!(adjCoinInfo.id == gameObject.GetComponent <coinAndroidTest>().id) && (adjCoinInfo.type == "small"))
                        {
                            if (!(adjCoinInfo.locked))
                            {
                                adjCoinIds.Add(adjCoinInfo.id);
                            }
                        }
                    }
                }

                if (cm2.state == 0)
                {
                    //foreach (int i in adjCoinIds){Debug.Log(i);}
                    cm2.handleFirst(adjCoinIds, gameObject.GetComponent <coinAndroidTest>().id, transform.position);
                }
                else                    //so state=1, on second coin. Need to first check to make sure that this coin is actually reachable from 1st coin
                {
                    bool terminate = true;
                    foreach (int i in cm2.reachableFromFirstCoin)
                    {
                        if (i == gameObject.GetComponent <coinAndroidTest>().id)
                        {
                            terminate = false;
                        }
                    }
                    if (terminate)
                    {
                        cm2.clearLines();                        //new
                        return;
                    }
                    cm2.handleSecond(adjCoinIds, gameObject.GetComponent <coinAndroidTest>().id, transform.position);
                }
            }
            else                //do the combining!
                                //for now just place on centroid, highest height + the .5, and average the healths of the 3 constituent coins
                                //ah bug here-need to make sure that there are 3 coins selected--just stick this in the merge

            {
                cm2.merge();
            }
        }
    }
Пример #5
0
    //for large coins only, swap for 3 small coins.
    void multiply()
    {
        GameObject s1 = (GameObject)Instantiate(smallcoin, gameObject.transform.position + .8f * (split1 + .5f * Vector3.up), gameObject.transform.rotation);

        if (gameObject.tag == "p1")
        {
            GameObject.Find("Game").GetComponent <testGame> ().addCoinToP1(s1);
        }
        else
        {
            GameObject.Find("Game").GetComponent <testGame> ().addCoinToP2(s1);
        }
        coinAndroidTest s1info = s1.GetComponent <coinAndroidTest>();

        s1info.locked = true;
        s1info.toggleLocked(true);

        GameObject s2 = (GameObject)Instantiate(smallcoin, gameObject.transform.position + .8f * (split2 + .5f * Vector3.up), gameObject.transform.rotation);

        if (gameObject.tag == "p1")
        {
            GameObject.Find("Game").GetComponent <testGame> ().addCoinToP1(s2);
        }
        else
        {
            GameObject.Find("Game").GetComponent <testGame> ().addCoinToP2(s2);
        }
        coinAndroidTest s2info = s2.GetComponent <coinAndroidTest>();

        s2info.locked = true;
        s2info.toggleLocked(true);

        GameObject s3 = (GameObject)Instantiate(smallcoin, gameObject.transform.position + .8f * (split3 + .5f * Vector3.up), gameObject.transform.rotation);

        if (gameObject.tag == "p1")
        {
            GameObject.Find("Game").GetComponent <testGame> ().addCoinToP1(s3);
        }
        else
        {
            GameObject.Find("Game").GetComponent <testGame> ().addCoinToP2(s3);
        }
        coinAndroidTest s3info = s3.GetComponent <coinAndroidTest>();

        s3info.locked = true;
        s3info.toggleLocked(true);

        if (gameObject.GetComponent <coinAndroidTest>().fireball)
        {
            s1info.fireball = true;
            s1.transform.GetComponentInChildren <Image>().color = new Color(1.0f, .6f, 0.0f);

            s2info.fireball = true;
            s2.transform.GetComponentInChildren <Image>().color = new Color(1.0f, .6f, 0.0f);

            s3info.fireball = true;
            s3.transform.GetComponentInChildren <Image>().color = new Color(1.0f, .6f, 0.0f);
        }

        if (gameObject.GetComponent <coinAndroidTest>().dynamite)
        {
            s1info.dynamite = true;
            s1.transform.GetComponentInChildren <Image>().color = new Color(174.0f / 255.0f, 28.0f / 255.0f, 152.0f / 255.0f);

            s2info.dynamite = true;
            s2.transform.GetComponentInChildren <Image>().color = new Color(174.0f / 255.0f, 28.0f / 255.0f, 152.0f / 255.0f);

            s3info.dynamite = true;
            s3.transform.GetComponentInChildren <Image>().color = new Color(174.0f / 255.0f, 28.0f / 255.0f, 152.0f / 255.0f);
        }

        float health = gameObject.GetComponentInChildren <Image>().fillAmount;

        s1.GetComponentInChildren <Image>().fillAmount = health;
        s2.GetComponentInChildren <Image>().fillAmount = health;
        s3.GetComponentInChildren <Image>().fillAmount = health;

        Destroy(gameObject);
    }
Пример #6
0
    void CastRayToWorld(Vector2 pos)
    {
        //Debug.Log ("initially: " + clicks);

        Ray r = Camera.main.ScreenPointToRay(pos);
        //Vector3 p = r.origin + r.direction*(10 - (-.17f));
        Vector3    p = Vector3.zero;
        RaycastHit test;
        LayerMask  lm;        //our layermask for raycasting to ignore coins not in turn

        if (turn == 1)        //so p1's turn want to mask out p2 coins. so mask out layer p2
        {
            lm = lm2;         //so lm2 is only layer p2. Then at end invert this.
        }
        else
        {
            lm = lm1;
        }
        lm = ~lm;

        bool       hitCoin = false;
        GameObject coinHit;

        //Debug.Log (lm.value);
        //Debug.Log (r.direction);
        if (Physics.Raycast(r.origin, r.direction, out test, Mathf.Infinity, lm))
        {
            //so need to check if hit a coin. else lower p.y else raise p.y (because if it's a coin then we're going to miss it if we incrase the ray's height..

            /*namely we know from that default unity cylinder primitive = 2 units high
             * this means due to .1 scale our coins are .2 units high so .2/2 = .1, the half height of interest.
             */
            p = test.point;

            GameObject gotHit = test.collider.gameObject;
            //Vector3 adjust = gotHit.transform.up;//so the normal of the surface that was hit
            //so need to make adjust to be terrain normal now..



            if (!gotHit.name.StartsWith("Terrain"))
            {
                if (clicks == 0)
                {
                    focus coinF = gotHit.GetComponent <focus>();
                    if (!coinF)
                    {
                        return;
                    }
                    coinF.handleSelection();
                    return;
                }

                //p.y -= .1f;//
                //Vector3 adjust = gotHit.transform.up; //try something else b/c when coin upside down, we get 0 -1 0 rather than 0 1 0.
                Vector3 adjust = test.normal;
                adjust.Normalize();


                //Debug.Log ("p prev: " + p);
                p += -.1f * adjust;               //AHA! So that's why. Adjust is being negative b/c coin is flipped over.
                //Debug.Log(adjust);
                //Debug.Log ("p adjusted: " + p + " and adjustment used: " + adjust);
                //Debug.Log("On a coin");
            }
            else                //so need the Terrain normal - credit to Eric on unity forumns
                                //p.y += .1f;

            /*
             * Terrain t = gotHit.GetComponent<Terrain>();
             * Vector3 relPos = p - t.transform.position;
             * Vector2 nPos = new Vector2(Mathf.InverseLerp(0.0f, t.terrainData.size.x, relPos.x), Mathf.InverseLerp(0.0f, t.terrainData.size.z, relPos.z));
             *
             * Vector3 adjust = t.terrainData.GetInterpolatedNormal(nPos.x,nPos.y);
             */
            //adjust = adjust.normalized;
            {
                deselectAllCoins();
                GameObject.Find("P1Merger").GetComponent <coinMerger>().clearLines();
                GameObject.Find("P2Merger").GetComponent <coinMerger>().clearLines();               //added



                //now if this coin has reachable pipeline emphasized(coin selected + pressed "S") and clicked on
                //a reachable segment, then teleport to some height above grid cell center (for now--later animate/lerp/rotate/roll)
                //and then reset clicks to 0 and return (not sure need to set to 0 as in already would be set to 0???)
                if (gotHit.GetComponent <SnapGrid>() != null)               // && storePipes.teleportationInitiated){
                {
                    SnapGrid sg = gotHit.GetComponent <SnapGrid>();
                    if (sg.selected)
                    {
                        //Debug.Log(sg.finalPosition[0]+.5f);
                        if (sg.owner == 1)
                        {
                            Vector3 teleportLoc = Vector3.zero;
                            teleportLoc.x = sg.finalPosition[0] + .5f;
                            teleportLoc.z = sg.finalPosition[1] + .5f;
                            storePipes.CoinThatCanTeleport.transform.position = teleportLoc;
                            storePipes.clearTeleportation();
                            storePipes.clearTeleportationP2();
                            clicks = 0;
                            return;                            //added
                        }
                        else
                        {
                            Vector3 teleportLoc = Vector3.zero;
                            teleportLoc.x = sg.finalPosition[0] + .5f;
                            teleportLoc.z = sg.finalPosition[1] + .5f;
                            storePipes.CoinThatCanTeleportP2.transform.position = teleportLoc;
                            storePipes.clearTeleportation();
                            storePipes.clearTeleportationP2();
                            clicks = 0;
                            return;
                        }
                    }
                }
                else
                {
                    storePipes.clearTeleportation();
                    storePipes.clearTeleportationP2();
                }

                Vector3 adjust = test.normal;
                adjust.Normalize();

                p += .1f * adjust;
                //Debug.Log("On the floor");
                //Debug.Log(adjust);
                //Debug.Log(gotHit.transform.up); aha, so transform.up gives the normal. need to use this for adjustment so that will work also on inclined surfaces,not just flat ones w/ normal of 0 1 0
            }
        }


        if (clicks == 0)
        {
            clickPos = p;
            clicks  += 1;
            //Debug.Log("h " + clicks);//added
        }
        else
        {
            clicks = 0;
            Vector3 dir = p - clickPos;

            //k so here rather than debug dray ray do a line renderer so viewer can see in scene

            StartCoroutine(drawLine(clickPos, p, 1.0f));

            Debug.DrawRay(clickPos, dir, Color.blue, 5.0f);
            RaycastHit hit;
            float      dist = dir.magnitude;
            if (Physics.Raycast(clickPos, dir, out hit, dist, lm))
            {
                GameObject target = hit.collider.gameObject;


                coinAndroidTest info = target.GetComponent <coinAndroidTest>();
                //if (info.owner != turn){return;} // so exit if WAIT NO use raycast layber bitmask and here just check for locked/set it if false to true and increment a var to decide if turn over
                if (!info)
                {
                    return;
                }
                if (info.locked)                //so this coin is locked meaning have already launched it
                {
                    return;
                }
                info.toggleLocked(true);
                info.locked = true;                 //so we're going to launch this so need to lock it so can't double launch in same turn


                Rigidbody coin = target.GetComponent <Rigidbody>();

                float distToHit = Vector3.Distance(hit.point, clickPos);

                float ratio = distToHit / dist;
                //Debug.Log("N/D: " + ratio);


                Vector3 offset = hit.point - coin.position;

                float offsetsize = offset.magnitude;
                //Debug.Log(offsetsize); offset = useless for coins--always = .5. For pencilwars (original) it had meaning...

                forceFactor = target.GetComponent <coinAndroidTest>().forceFactor;

                Vector3 forceToAdd = dir.normalized * ratio * forceFactor;                // * Mathf.Pow (offsetsize,spower);
                //Debug.Log(coin.name + forceToAdd);
                coin.AddForceAtPosition(forceToAdd, hit.point);
            }
        }

        //Debug.Log ("at the end: " + clicks);
    }
Пример #7
0
    void OnTriggerEnter(Collider other)
    {
        GameObject powerUp = other.gameObject;

        if (powerUp.tag == "fireball")
        {
            powerUp.SetActive(false);
            dynamite = false;
            fireball = true;
            gameObject.transform.GetComponentInChildren <Image>().color = firecolor;
            //Debug.Log("got you!");
        }
        if (powerUp.tag == "dynamite")
        {
            powerUp.SetActive(false);
            fireball = false;
            dynamite = true;
            gameObject.transform.GetComponentInChildren <Image>().color = dynamitecolor;
        }
        if (powerUp.tag == "mirror")
        {
            if (owner == 1)
            {
                powerUp.SetActive(false);
                //Debug.Log(myR.velocity);

                GameObject p1clone = (GameObject)Instantiate(p1coin, gameObject.transform.position - spawnRadius * myR.velocity.normalized, myR.rotation);
                GameObject.Find("Game").GetComponent <testGame> ().addCoinToP1(p1clone);
                p1clone.GetComponent <Rigidbody>().velocity = myR.velocity;
                coinAndroidTest p1cloneinfo = p1clone.GetComponent <coinAndroidTest>();
                p1cloneinfo.locked = true;                //locked
                //give the clone my state
                if (dynamite)
                {
                    p1cloneinfo.dynamite = true;
                    p1cloneinfo.transform.GetComponentInChildren <Image>().color = dynamitecolor;
                }
                if (fireball)
                {
                    p1cloneinfo.fireball = true;
                    p1cloneinfo.transform.GetComponentInChildren <Image>().color = firecolor;
                }
                //Debug.Log("p1 (yellow) hit me");
            }
            else
            {
                powerUp.SetActive(false);
                //Debug.Log(myR.velocity);

                GameObject p2clone = (GameObject)Instantiate(p2coin, gameObject.transform.position - spawnRadius * myR.velocity.normalized, myR.rotation);
                GameObject.Find("Game").GetComponent <testGame> ().addCoinToP2(p2clone);
                p2clone.GetComponent <Rigidbody>().velocity = myR.velocity;
                coinAndroidTest p2cloneinfo = p2clone.GetComponent <coinAndroidTest>();
                //p2cloneinfo.locked = true;//locked

                //give the clone my state
                p2cloneinfo.locked = locked;
                if (locked)
                {
                    p2cloneinfo.toggleLocked(true);
                }
                if (dynamite)
                {
                    p2cloneinfo.dynamite = true;
                    p2cloneinfo.transform.GetComponentInChildren <Image>().color = dynamitecolor;
                }
                if (fireball)
                {
                    p2cloneinfo.fireball = true;
                    p2cloneinfo.transform.GetComponentInChildren <Image>().color = firecolor;
                }
                //Debug.Log("p2 (red) hit me");
            }
        }
    }