public void resetBall() { Spawnmanager.ResetManager(); LastTouched = Ballstate.HasNotTouchedAnything; GetComponent <CamShakeSimple> ().enableshake = false; Row1 = false; Orange.GetComponent <TrailRenderer> ().enabled = false; Blue.GetComponent <TrailRenderer> ().enabled = false; White.GetComponent <TrailRenderer> ().enabled = false; GetComponent <CamShakeSimple> ().enableshake = false; Row2 = false; Row3 = false; //væk med trails Orange.GetComponent <TrailRenderer> ().time = 0; Blue.GetComponent <TrailRenderer> ().time = 0; White.GetComponent <TrailRenderer> ().time = 0; var vel = GetComponent <Rigidbody2D> ().velocity; vel.y = 0; vel.x = 0; GetComponent <Rigidbody2D> ().velocity = vel; gameObject.transform.position = new Vector2(0, 0); GameObject exp2 = Instantiate(Electric) as GameObject; exp2.transform.position = transform.position; StartCoroutine(hi(2.0f)); hi(0.5f); //Reset Blockzzz foreach (Transform g in LB) { print(g.name); g.gameObject.SetActive(true); if (g.GetComponent <Renderer> ()) { g.GetComponent <Renderer> ().enabled = true; } } foreach (Transform g in RB) { print("Ramte block: " + g.name); g.gameObject.SetActive(true); if (g.GetComponent <Renderer> ()) { g.GetComponent <Renderer> ().enabled = true; } } //Spawnmanager.ResetManager(); print("BALL HAS BEEN RESET"); }
///// <summary> ///// 构造函数:此时其它球还未生成,所以这里是取不到其它球的包括0.<MotherBall>(); ///// </summary> //public Ball() //{ // GetAllBalls(); //} ///// <summary> ///// 给Ball[] balls赋值/获取到16个球代码组件 ///// </summary> //void GetAllBalls() //{ // balls[0] = GameObject.Find("0").GetComponent<MotherBall>(); // for (int i = 1; i < balls.Length; i++) // { // balls[i] = GameObject.Find(i.ToString()).GetComponent<SonBall>(); // } //} /// <summary> /// 设置状态方法;//写成虚方法:因为子类切换状态后的行为不同,所有球离开Movement状态都需要判断所有球的当前状态以初始化球杆,但白球进入球袋状态,需要转入待归位状态; /// </summary> public virtual void SetState() { //假如其中一颗球进入Stop状态或进入InPocket状态,则判断其它球是否都不是Movement状态,只要全部不是Movement则等待0.5秒实例化球杆 float nowSpeed = transform.rigidbody.velocity.magnitude; if (transform.position.y < 3f && nowSpeed < stopSpeed) { this.state = Ballstate.InPocket; } else if (nowSpeed < stopSpeed) { this.state = Ballstate.Stop; } else { this.state = Ballstate.Movement; } }
void OnCollisionEnter2D(Collision2D coll) { print(coll.collider.name); if (GetComponent <Rigidbody2D> ().velocity.magnitude < 5 && Time.timeScale == 1) { GetComponent <Rigidbody2D> ().velocity = new Vector2(GetComponent <Rigidbody2D> ().velocity.x * 1.25f, GetComponent <Rigidbody2D> ().velocity.y * 1.25f); } if (coll.collider.CompareTag("Player")) { GetComponent <AudioSource> ().PlayOneShot(Playerhit); print("lortet er f****d"); var velY = GetComponent <Rigidbody2D> ().velocity.y; var velX = GetComponent <Rigidbody2D> ().velocity.x; velY = (velY / 2.0f) + (coll.collider.GetComponent <Rigidbody2D> ().velocity.y / 3.0f); GetComponent <Rigidbody2D> ().velocity = new Vector2(velX, velY); if (GetComponent <Rigidbody2D> ().velocity.magnitude < twofast4game) { GetComponent <Rigidbody2D> ().velocity *= 1.2f; } if (GetComponent <Rigidbody2D> ().transform.position.y > LastY - 0.2f && GetComponent <Rigidbody2D> ().transform.position.y < LastY + 0.2f) { HitInRow += 1; // print ("LASTYVIRKER"); // print (HitInRow); } else { HitInRow = 0; } //HitInRow if (HitInRow > 2) { if (GetComponent <Rigidbody2D> ().transform.position.y > 0) { GetComponent <Rigidbody2D> ().AddForce(Vector2.down * 20); GetComponent <Rigidbody2D> ().velocity *= 0.75f; } else { GetComponent <Rigidbody2D> ().AddForce(Vector2.up * 20); GetComponent <Rigidbody2D> ().velocity *= 0.75f; } } LastY = GetComponent <Rigidbody2D> ().transform.position.y; print("f**k"); if (coll.collider.name == ("Player1")) { LastTouched = Ballstate.HasNotTouchedAnything; LastPlayer = 1; Orange.GetComponent <TrailRenderer> ().time = 1; Blue.GetComponent <TrailRenderer> ().time = 0; White.GetComponent <TrailRenderer> ().time = 0; if (Row2 == true) { GameObject exp = Instantiate(BoomOrange) as GameObject; exp.transform.position = transform.position; } } if (coll.collider.name == ("Player2")) { LastTouched = Ballstate.HasNotTouchedAnything; LastPlayer = 2; Orange.GetComponent <TrailRenderer> ().time = 0; Blue.GetComponent <TrailRenderer> ().time = 1; White.GetComponent <TrailRenderer> ().time = 0; if (Row2 == true) { GameObject exp2 = Instantiate(BoomBlue) as GameObject; exp2.transform.position = transform.position; } } } //BLOCKS if (coll.collider.CompareTag("Block")) { GetComponent <AudioSource> ().PlayOneShot(Blockhit); GameObject trekanter = Instantiate(Trekantexp) as GameObject; trekanter.transform.position = coll.contacts [0].point; Destroy(trekanter, 2.9f); Orange.GetComponent <TrailRenderer> ().time = 0; Blue.GetComponent <TrailRenderer> ().time = 0; White.GetComponent <TrailRenderer> ().time = 1; // kører blockhack StartCoroutine(BlockHack(coll.collider.gameObject)); } if (coll.collider.name == "R_lvl1") { LastTouched = Ballstate.RightTouched; if (LastPlayer == 2) { GameObject Spark2 = Instantiate(SparkBlue) as GameObject; Spark2.transform.position = coll.contacts [0].point; } if (LastPlayer == 1) { GameObject Spark1 = Instantiate(SparkOrange) as GameObject; Spark1.transform.position = coll.contacts [0].point; } if (GetComponent <Rigidbody2D> ().velocity.magnitude > 20) { GetComponent <Rigidbody2D> ().velocity *= 0.66f; } if (GetComponent <Rigidbody2D> ().velocity != Vector2.zero) { KortPause = GetComponent <Rigidbody2D> ().velocity; } row1thing(); } if (coll.collider.name == "L_lvl1") { LastTouched = Ballstate.LeftTouched; if (LastPlayer == 2) { GameObject Spark2 = Instantiate(SparkBlue) as GameObject; Spark2.transform.position = coll.contacts [0].point; } if (LastPlayer == 1) { GameObject Spark1 = Instantiate(SparkOrange) as GameObject; Spark1.transform.position = coll.contacts [0].point; } if (GetComponent <Rigidbody2D> ().velocity.magnitude > 20) { GetComponent <Rigidbody2D> ().velocity *= 0.66f; } if (GetComponent <Rigidbody2D> ().velocity != Vector2.zero) { KortPause = GetComponent <Rigidbody2D> ().velocity; } row1thing(); } if (coll.collider.name == "R_lvl2") { LastTouched = Ballstate.RightTouched; if (LastPlayer == 2) { GameObject Spark2 = Instantiate(SparkBlue) as GameObject; Spark2.transform.position = coll.contacts [0].point; } if (LastPlayer == 1) { GameObject Spark1 = Instantiate(SparkOrange) as GameObject; Spark1.transform.position = coll.contacts [0].point; } if (GetComponent <Rigidbody2D> ().velocity.magnitude > 20) { GetComponent <Rigidbody2D> ().velocity *= 0.75f; } if (GetComponent <Rigidbody2D> ().velocity != Vector2.zero) { KortPause = GetComponent <Rigidbody2D> ().velocity; } row2thing(); } if (coll.collider.name == "L_lvl2") { LastTouched = Ballstate.LeftTouched; if (LastPlayer == 2) { GameObject Spark2 = Instantiate(SparkBlue) as GameObject; Spark2.transform.position = coll.contacts [0].point; } if (LastPlayer == 1) { GameObject Spark1 = Instantiate(SparkOrange) as GameObject; Spark1.transform.position = coll.contacts [0].point; } if (GetComponent <Rigidbody2D> ().velocity.magnitude > 20) { GetComponent <Rigidbody2D> ().velocity *= 0.75f; } if (GetComponent <Rigidbody2D> ().velocity != Vector2.zero) { KortPause = GetComponent <Rigidbody2D> ().velocity; } row2thing(); } if (coll.collider.name == "R_lvl3") { LastTouched = Ballstate.RightTouched; if (LastPlayer == 2) { GameObject Spark2 = Instantiate(SparkBlue) as GameObject; Spark2.transform.position = coll.contacts [0].point; } if (LastPlayer == 1) { GameObject Spark1 = Instantiate(SparkOrange) as GameObject; Spark1.transform.position = coll.contacts [0].point; } if (GetComponent <Rigidbody2D> ().velocity.magnitude > 20) { GetComponent <Rigidbody2D> ().velocity *= 0.75f; } if (GetComponent <Rigidbody2D> ().velocity != Vector2.zero) { KortPause = GetComponent <Rigidbody2D> ().velocity; } row3thing(); } if (coll.collider.name == "L_lvl3") { LastTouched = Ballstate.LeftTouched; if (LastPlayer == 2) { GameObject Spark2 = Instantiate(SparkBlue) as GameObject; Spark2.transform.position = coll.contacts [0].point; } if (LastPlayer == 1) { GameObject Spark1 = Instantiate(SparkOrange) as GameObject; Spark1.transform.position = coll.contacts [0].point; } if (GetComponent <Rigidbody2D> ().velocity.magnitude > 20) { GetComponent <Rigidbody2D> ().velocity *= 0.75f; } if (GetComponent <Rigidbody2D> ().velocity != Vector2.zero) { KortPause = GetComponent <Rigidbody2D> ().velocity; } row3thing(); } if (coll.collider.name == "R_lvl4") { LastTouched = Ballstate.RightTouched; if (LastPlayer == 2) { GameObject Spark2 = Instantiate(SparkBlue) as GameObject; Spark2.transform.position = coll.contacts [0].point; } if (LastPlayer == 1) { GameObject Spark1 = Instantiate(SparkOrange) as GameObject; Spark1.transform.position = coll.contacts [0].point; } if (GetComponent <Rigidbody2D> ().velocity.magnitude > 20) { GetComponent <Rigidbody2D> ().velocity *= 0.75f; } if (GetComponent <Rigidbody2D> ().velocity != Vector2.zero) { KortPause = GetComponent <Rigidbody2D> ().velocity; } // StartCoroutine (Kunstnerpause4 ()); } if (coll.collider.name == "L_lvl4") { LastTouched = Ballstate.LeftTouched; if (LastPlayer == 2) { GameObject Spark2 = Instantiate(SparkBlue) as GameObject; Spark2.transform.position = coll.contacts [0].point; } if (LastPlayer == 1) { GameObject Spark1 = Instantiate(SparkOrange) as GameObject; Spark1.transform.position = coll.contacts [0].point; } if (GetComponent <Rigidbody2D> ().velocity.magnitude > 20) { GetComponent <Rigidbody2D> ().velocity *= 0.75f; } if (GetComponent <Rigidbody2D> ().velocity != Vector2.zero) { KortPause = GetComponent <Rigidbody2D> ().velocity; } // StartCoroutine (Kunstnerpause4 ()); } print(LastTouched); }