Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        frame++;
        ++count;
        if (count % 15 == 0)
        {
            Destroy(anima);
        }
        if (transform.position.y < -5.5f || transform.position.y > 5.5f || blood.num <= 0)
        {
            //结尾动画
            //GameObject.Find("ObjectName").GetComponent<MainControl>().enabled = false;
            TerminateFunction();
        }


        if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
        {
            sheet.Play("move_right");

            transform.Translate(Vector3.right * speed * Time.deltaTime * 2.0f);
        }
        if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
        {
            sheet.Play("move_left");
            transform.Translate(Vector3.left * speed * Time.deltaTime * 2.0f);
        }
        BoardsUp();
        blood.Show();
        coin.Show();
        //monster ai
        GameObject ai = GameObject.Find("AI");

        if (frame % 480 == 0)
        {
            ai.transform.position = new Vector3(-ai.transform.position.x, 0, 0);
        }
        if (frame % 60 == 0)
        {
            movvec = -movvec;
        }
        ai.transform.Translate(movvec * aimovspeed * Time.deltaTime);

        Vector3 mainposition = (Vector3)transform.position;
        Vector3 aiposition   = (Vector3)ai.transform.position;
        Vector3 movdirection = mainposition - aiposition;

        if (frame % 120 == 0)
        {
            GameObject bul_anim = (GameObject)Resources.Load("Prefab/green_bullet");
            GameObject bul      = Instantiate(bul_anim);
            bul.transform.localScale = new Vector3(1.50f, 1.50f, 1.0f);

            bul.transform.position = (Vector3)aiposition;
            bul.name = "bullet";

            bullet.Add(bul);
            Vector3 bulletmovvector = (Vector3)movdirection;
            bulletmovdirection.Add((Vector3)bulletmovvector);
        }
        for (int i = 0; i < bulletmovdirection.Count;)
        {
            GameObject obj = (GameObject)bullet[i];
            Vector3    vec = (Vector3)bulletmovdirection[i];
            obj.transform.Translate(vec * Time.deltaTime);
            if (obj.transform.position.x < -7.0f || obj.transform.position.x > 7.0f || obj.transform.position.y > 5.5f || obj.transform.position.y < -5.5f || obj.name == "nonactive")
            {
                bullet.Remove(obj);
                Destroy(obj);
                bulletmovdirection.Remove(vec);
            }
            else
            {
                i++;
            }
        }
        //bullet ai

        for (int i = 0; i < bomb.Count;)
        {
            GameObject obj = (GameObject)bomb[i];

            int preframe = (int)bombtime[i];

            if (frame - preframe == 20)
            {
                bomb.Remove(obj);
                Destroy(obj);
                bombtime.Remove(preframe);
            }
            else
            {
                i++;
            }
        }

        //elf ai
        if (frame == 300)
        {
            GameObject elf_now = (GameObject)Resources.Load("Prefab/elf");
            elf = Instantiate(elf_now);
            elf.transform.localScale = new Vector3(0.8f, 0.8f, 0.1f);
            elf.transform.position   = new Vector3(0, 0, 0);
            elf.GetComponent <Renderer>().material.mainTexture = (Texture)Resources.Load("elf");
        }
        if (frame > 300)
        {
            Vector3 elfposition  = (Vector3)elf.transform.position;
            Vector3 elfdirection = mainposition - elfposition;
            elf.transform.Translate(elfdirection * elfmovspeed * Time.deltaTime);
            if (frame % 60 == 0)
            {
                blood.add2();
            }
        }
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        // Debug.Log(isGoldAway ? "GoldAway" : "GoldNotAway");
        Debug.Log(NumberOfMP);
        frame++;
        ++count;
        if (count % 15 == 0)
        {
            Destroy(anima);
        }
        bool haspet = UserInfo.PETS;

        Debug.Log(UserInfo.PETS.ToString());
        Vector3 mainposition = (Vector3)transform.position;

        if (frame == 300 && haspet == true)
        {
            GameObject elf_now = (GameObject)Resources.Load("Prefab/elf");
            elf = Instantiate(elf_now);
            elf.transform.localScale = new Vector3(0.8f, 0.8f, 0.1f);
            elf.transform.position   = new Vector3(0, 0, 0);
            elf.GetComponent <Renderer>().material.mainTexture = (Texture)Resources.Load("elf");
        }
        if (frame > 300 && haspet == true)
        {
            Vector3 elfposition  = (Vector3)elf.transform.position;
            Vector3 elfdirection = mainposition - elfposition;
            elf.transform.Translate(elfdirection * elfmovspeed * Time.deltaTime);
            if (frame % 60 == 0)
            {
                blood.add2();
            }
        }
        if (transform.position.y < -5.5f || blood.num <= 0)
        {
            //结尾动画
            //GameObject.Find("ObjectName").GetComponent<MainControl>().enabled = false;
            TerminateFunction();
        }

        if (transform.position.y > 5.5f)
        {
            ready_to_subHp = true;
        }
        if (ready_to_subHp && transform.position.y < 5.5f)
        {
            ready_to_subHp = false;

            blood.sub20();
            camera_.shake();
        }

        if (((forcetool.currentVelocity.x < 0.01) && (forcetool.currentVelocity.x > -0.01)) && (forcetool.force.y < 0.05) && (forcetool.force.y > -0.05) && (!is_run))
        {
            sheet.Play("stand");
        }
        if ((Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)))
        {
            transform.Translate(Vector3.right * speed * Time.deltaTime * 2.0f);
            left_on = true;
            if ((forcetool.force.y < 0.05) && (forcetool.force.y > -0.05) && !is_run)
            {
                sheet.Play("move_right");
                is_run = true;
            }
        }
        if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
        {
            transform.Translate(Vector3.left * speed * Time.deltaTime * 2.0f);
            right_on = true;
            if ((forcetool.force.y < 0.05) && (forcetool.force.y > -0.05) && !is_run)
            {
                sheet.Play("move_left");
                is_run = true;
            }
        }

        if (Input.GetKeyUp(KeyCode.D) || Input.GetKeyUp(KeyCode.RightArrow))
        {
            is_run   = false;
            right_on = false;
            if ((forcetool.force.y < 0.05) && (forcetool.force.y > -0.05))
            {
                sheet.Play("stand");
            }
            else
            {
                sheet.Play("in_air_right");
            }
        }
        if (Input.GetKeyUp(KeyCode.A) || Input.GetKeyUp(KeyCode.LeftArrow))
        {
            is_run  = false;
            left_on = false;
            if ((forcetool.force.y < 0.05) && (forcetool.force.y > -0.05))
            {
                sheet.Play("stand");
            }
            else
            {
                sheet.Play("in_air_left");
            }
        }
        if ((forcetool.force.y < -0.9) && (right_on) && !is_jumping)
        {
            sheet.Play("in_air_right");
            is_run = false;
        }
        if ((forcetool.force.y < -0.9) && (left_on) && !is_jumping)
        {
            sheet.Play("in_air_left");
            is_run = false;
        }
        if (!is_jumping && (ready_to_jump))
        {
            sheet.Play("jump");
            jump_count = 0;
            is_jumping = true;
        }
        if (is_jumping)
        {
            jump_count++;
        }
        if (jump_count >= 90)
        {
            jump_count    = 0;
            is_jumping    = false;
            ready_to_jump = false;
        }
        BoardsUp();
        blood.Show();
        coin.Show();
        //Vector3 mainposition = (Vector3)transform.position;
        //monster ai

        if (frame == 1800)
        {
            GameObject AI_robot = (GameObject)Resources.Load("Prefab/monster");
            GameObject airobot  = Instantiate(AI_robot);
            airobot.transform.localScale = new Vector3(1.5f, 1.5f, 1.0f);
            airobot.transform.position   = new Vector3(6.0f, 0, 0);
            airobot.name = "AI";


            if (airobot_text.name != null)
            {
                airobot_text.AddComponent <TextMesh>();
                airobot_text.transform.localScale           = new Vector3(0.05f, 0.05f, 1);
                airobot_text.GetComponent <TextMesh>().text = "Hhhh! Finally, I find you!";
                //airobot_text.GetComponent<TextMesh>().font = "Fonts/Arial";
                airobot_text.GetComponent <TextMesh>().fontSize = 150;

                airobot_text.transform.localRotation = new Quaternion(0, 180, 0, 0);
                //airobot_text.transform.position = airobot.transform.position;

                Vector3 airobot_pos = airobot.transform.position;

                airobot_pos.x -= 3.0f;
                airobot_pos.y += 2.0f;

                airobot_text.transform.position = airobot_pos;
            }
            //GameObject airobot_text = GameObject.Find("Canvas/ai_text").GetComponent<Text>();
        }
        if (frame == 1800)
        {
            //laugh.volume =
            laugh.Play();
        }
        if (frame > 1890)
        {
            //airobot_text.name = "noactive";
            if (airobot_text != null)
            {
                Destroy(airobot_text);
            }
        }
        if (frame > 1800)
        {
            GameObject ai = GameObject.Find("AI");
            if (frame % 480 == 0)
            {
                ai.transform.position = new Vector3(-ai.transform.position.x, 0, 0);
            }
            if (frame % 60 == 0)
            {
                movvec = -movvec;
            }
            ai.transform.Translate(movvec * aimovspeed * Time.deltaTime);


            Vector3 aiposition   = (Vector3)ai.transform.position;
            Vector3 movdirection = mainposition - aiposition;
            if (frame % 60 == 0 && bulspeed > 40)
            {
                bulspeed--;
            }

            if (frame % bulspeed == 0)
            {
                GameObject bul_anim = (GameObject)Resources.Load("Prefab/green_bullet");
                GameObject bul      = Instantiate(bul_anim);
                bul.transform.localScale = new Vector3(1.50f, 1.50f, 1.0f);

                bul.transform.position = (Vector3)aiposition;
                bul.name = "bullet";

                bullet.Add(bul);
                Vector3 bulletmovvector = (Vector3)movdirection;
                bulletmovdirection.Add((Vector3)bulletmovvector);
            }
            for (int i = 0; i < bulletmovdirection.Count;)
            {
                GameObject obj = (GameObject)bullet[i];
                Vector3    vec = (Vector3)bulletmovdirection[i];
                obj.transform.Translate(vec * Time.deltaTime);
                if (obj.transform.position.x < -7.0f || obj.transform.position.x > 7.0f || obj.transform.position.y > 5.5f || obj.transform.position.y < -5.5f || obj.name == "nonactive")
                {
                    bullet.Remove(obj);
                    Destroy(obj);
                    bulletmovdirection.Remove(vec);
                }
                else
                {
                    i++;
                }
            }
        }
        for (int i = 0; i < framearray.Count;)
        {
            GameObject obj      = (GameObject)breakarray[i];
            int        preframe = (int)framearray[i];

            if (frame - preframe == 30)
            {
                breakarray.Remove(obj);
                Destroy(obj);
                framearray.Remove(preframe);
            }
            else
            {
                i++;
            }
        }
        //bullet ai

        for (int i = 0; i < bomb.Count;)
        {
            GameObject obj = (GameObject)bomb[i];

            int preframe = (int)bombtime[i];

            if (frame - preframe == 20)
            {
                bomb.Remove(obj);
                Destroy(obj);
                bombtime.Remove(preframe);
            }
            else
            {
                i++;
            }
        }

        //elf ai
    }