示例#1
0
    // Update is called once per frame
    void Update()
    {
        //StartCoroutine (PlayPunch ());

        //if another animation isn't going, do idle animation
        if (!inAnim)
        {
            anim = "loop_idle";
        }

        //if bot1 is jumping
        if (gameObject.tag == "Bot1" && Input.GetButton("Jump"))
        {
            StartCoroutine(WaitForAnimation(animation, "jump"));

            //if bot1 is running
        }
        else if (gameObject.tag == "Bot1" && (Input.GetButton("Vertical") || Input.GetButton("Horizontal")))
        {
            //only do running animation if another one isn't going
            if (!inAnim)
            {
                anim = "loop_run_funny";
                animation ["loop_run_funny"].speed = 7.0f;
            }

            //if bot2 is jumping
        }
        else if (gameObject.tag == "Bot2" && Input.GetButton("Jump_alt"))
        {
            ;
            StartCoroutine(WaitForAnimation(animation, "jump"));

            //if bot2 is running
        }
        else if (gameObject.tag == "Bot2" && (Input.GetButton("Vertical_alt") || Input.GetButton("Horizontal_alt")))
        {
            //only do running animation if another one isn't going
            if (!inAnim)
            {
                anim = "loop_run_funny";
                animation ["loop_run_funny"].speed = 7.0f;
            }
        }

        if (!punched)
        {
            /*Direction1 will be split with
             * 1 = North
             * 2 = East
             * 3 = South
             * 4 = West
             * Direction2 will be split with
             * 0 = base height
             * 1 = up
             * 2 = down
             * This combo allows if Direct2 != 0, Direct1's outcome is used while if direct2  is 1 or 2 they override the impact direction
             * */
            if (camera.transform.eulerAngles.x >= 270 && camera.transform.eulerAngles.x <= 315)
            {
                dire2 = 1;
            }
            else if (camera.transform.eulerAngles.x >= 45 && camera.transform.eulerAngles.x <= 90)
            {
                dire2 = 2;
            }
            else
            {
                dire2 = 0;
            }
            if (player.transform.eulerAngles.y <= 135 && player.transform.eulerAngles.y > 45)
            {
                dire1 = 2;
            }
            else if (player.transform.eulerAngles.y <= 225 && player.transform.eulerAngles.y > 135)
            {
                dire1 = 3;
            }
            else if (player.transform.eulerAngles.y <= 315 && player.transform.eulerAngles.y > 225)
            {
                dire1 = 4;
            }
            else
            {
                dire1 = 1;
            }
        }

        if (/*anim != "punch_hi_left" && anim != "punch_hi_right" &&*/ ((gameObject.tag == "Bot1" && Input.GetButton("Punch")) || (gameObject.tag == "Bot2" && Input.GetButton("Punch_alt"))))
        {
            if (Random.Range(0f, 1f) < 0.5f)
            {
                anim = "punch_hi_left";
            }
            else
            {
                anim = "punch_hi_right";
            }

            //punchSound = Resources.Load<AudioClip> ("servo13");
            //AudioSource.PlayClipAtPoint(punchSound,transform.position);
//			audio.clip = punchSound;
//			audio.Play ();

            //only run punch animation if another one isn't going.
            //this is so if we rapidly click the punch button, we don't
            //just repeat the first 0.1 seconds of the punch animation over
            //and over
            if (!inAnim)
            {
                StartCoroutine(WaitForAnimation(animation, anim));
                //punchSound = Resources.Load<AudioClip> ("servo2");
                //StartCoroutine (PlayPunch ());

                //AudioSource.PlayClipAtPoint(punchSound,transform.position);
                //audio.clip = punchSound;
                //audio.Play ();
            }

            punched = true;
            gOut    = true;
            hasHit  = false;
            //canPunch = false;
        }
        else
        {
            //if the fist running this script is the fist we want to be punching right now
            //canPunch = false;
            if (gOut)
            {
                Ray        ray;
                RaycastHit hit;

                //Debug.DrawRay (transform.position, Vector3.left, Color.green, 5f);
                ray = new Ray(fist.transform.position, fist.transform.forward);
                //ray = new Ray (transform.position, Vector3.left);
                if (Physics.Raycast(ray, out hit))
                {
                    if (hit.distance < 1.85f)
                    {
                        if (hit.collider.tag == "Terrain" && !hasHit)
                        {
                            //Debug.Log ("2");
                            //mt.ReplaceBlockCenter(20,0);
                            Vector3 position = hit.point;
                            position += (hit.normal * -0.5f);
                            int x = Mathf.RoundToInt(position.x);
                            int y = Mathf.RoundToInt(position.y);
                            int z = Mathf.RoundToInt(position.z);
                            if (mt.world.data [x, y, z] == 3)
                            {
                                //Debug.Log ("HealInc");
                                bool powerupCheck = PowerUpGrab();
                                while (powerupCheck == false)
                                {
                                    powerupCheck = PowerUpGrab();
                                }
                            }
                            if (gameObject.tag == "Bot1")
                            {
                                mt.ReplaceBlockExplodeDirection(dire1, dire2, p1.pow, hit, 0);
                            }
                            if (gameObject.tag == "Bot2")
                            {
                                mt.ReplaceBlockExplodeDirection(dire1, dire2, p2.pow, hit, 0);
                            }
                            //mt.ReplaceBlockExplode(0,hit,0);
                            gOut   = false;
                            hasHit = true;
                            //punched = false;
                        }
                        if ((hit.collider.tag == "P1Hit" || hit.collider.tag == "Player1" && !hasHit) && gameObject.tag == "Bot2" && p2CanPunch)
                        {
                            StartCoroutine(PunchCooldown(2));
                            p1.applyHit();
                            hasHit = true;
                            gOut   = false;
                            //punched = false;
                        }
                        if ((hit.collider.tag == "P2Hit" || hit.collider.tag == "Player2" && !hasHit) && gameObject.tag == "Bot1" && p1CanPunch)
                        {
                            StartCoroutine(PunchCooldown(1));
                            p2.applyHit();
                            hasHit = true;
                            gOut   = false;
                            //punched = false;
                        }
                    }
                }
                else
                {
                    hasHit  = true;
                    punched = false;
                    //canPunch = true;
                }
            }
        }

        currentAnim.CrossFade(anim);
    }