// 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 }
void OnCollisionEnter(Collision thing) { if (transform.position.y > 4.3f) { for (int i = 0; i < boards.Count; i++) { GameObject obj = (GameObject)boards[i]; obj.GetComponent <BoxCollider>().enabled = false; } blood.sub20(); camera_.shake(); if (blood_screen.GetComponent <BloodScreen>().flag == false) { blood_screen.GetComponent <BloodScreen>().flag = true; } } else { var name = thing.collider.name; //Debug.Log("Thing is " + name); if (name == "cube2") { ContactPoint vPoint = thing.contacts[0]; if (vPoint.normal.y > 0) { ci.Play(); blood.add(); if (blood_screen.GetComponent <BloodScreen>().flag == false) { blood_screen.GetComponent <BloodScreen>().flag = true; } } } else if (name == "cube3") { putong.Play(); //Destroy(thing.collider); } else if (name == "cube4") { putong.Play(); } else if (name == "cube5") { Debug.Log(name); ContactPoint vPoint = thing.contacts[0]; //获取第一个碰撞点 Quaternion quate = Quaternion.FromToRotation(Vector3.up, new Vector3(0, 1, 0)); //碰撞点法线 count = 0; suilie.Play(); anima = Instantiate(break_brick_anim, vPoint.point, quate) as GameObject; breakarray.Add(anima); framearray.Add(frame); boards.Remove(thing.gameObject); Destroy(thing.gameObject); } else if (name == "cube6") { ContactPoint vPoint = thing.contacts[0]; if (vPoint.normal.y > 0) { transform.Translate(new Vector3(0, 8, 0) * speed * Time.deltaTime); is_jumping = false; ready_to_jump = true; tanhuang.Play(); } } else if (name == "cube1") { putong.Play(); } else if (name == "bullet") { blood.add(); Bomb.Play(); GameObject bul_explore = Instantiate(bullet_explore_anim); bul_explore.transform.localScale = new Vector3(2.0f, 2.0f, 1.0f); ContactPoint vPoint = thing.contacts[0]; //获取第一个碰撞点 Quaternion quate = Quaternion.FromToRotation(Vector3.up, vPoint.normal); //碰撞点法线 GameObject animation = Instantiate(bul_explore, vPoint.point, quate) as GameObject; bomb.Add(animation); bombtime.Add(frame); thing.gameObject.name = "nonactive"; Destroy(bul_explore); } // Collision on GoldCoins else if (name == "GoldCoin") { GetCoins.Play(); isGoldAway = true; // Go to an inaccessible place // RealGC.transform.position = new Vector3 (10000.0f, 10000.0f, 0); // RealGC.transform.position = new Vector3(0.08f, -6.9f, 0); Destroy(RealGC); // Coin add one coin.Add(1); } // Collision on MagicPotion else if (name == "MagicPotionOne") { GetMagicPotions.Play(); isMP1Away = true; Destroy(RealMP1); // NumberOfMP--; // RealMP1.transform.position = new Vector3(0.08f, -6.9f, 0); //new Vector3 (10000.0f, 10000.0f, 0); // HP add some blood.add3(); } else if (name == "MagicPotionTwo") { GetMagicPotions.Play(); isMP2Away = true; Destroy(RealMP2); NumberOfMP--; RealMP2.transform.position = new Vector3(0.08f, -6.9f, 0); //new Vector3 (10000.0f, 10000.0f, 0); // HP add some blood.add3(); } } }