void FixedUpdate() { Vector3 fwd = transform.TransformDirection(Vector3.forward); /*if (Physics.Raycast(transform.position, fwd, out hitInfo, 10)) * { * GameObject hitObject = hitInfo.collider.gameObject; * if (hitObject != previousObj) * { * duration = 0.0f; * previousObj = hitObject; * } * else * { * duration += Time.deltaTime; * if (duration > 2.0f) * { * if (hitObject.name == "Brick(Clone)") * { * Vector3 forward = transform.TransformDirection(Vector3.forward); * GameObject newball = Instantiate(ball, Camera.GetComponent<Transform>().localPosition, Camera.GetComponent<Transform>().rotation).gameObject; * newball.GetComponent<Rigidbody>().velocity = 30.0f * forward; * } * else if (hitObject.name == "ground") * { * Camera.transform.position = new Vector3(hitInfo.point.x, Camera.transform.position.y, hitInfo.point.z); * } * else if (hitObject.name == "Reset") * { * Camera.transform.position = new Vector3(0.0f, 0.5f, 0.0f); * foreach (Transform child in tower) * { * Destroy(child.gameObject); * } * rebuild = true; * } * duration = 0.0f; * } * } * } * //else * { * duration = 0.0f; * }*/ if (Physics.Raycast(Camera.transform.position, Camera.transform.forward, out hitInfo, 10)) { Collider collider = hitInfo.collider; if (collider != LookingObj) { if (LookingObj != null) { var particle = LookingObj.GetComponent <ParticleSystem>(); if (particle != null) { particle.Stop(); } if (LookingObj.name == "Brick(Clone)") { LookingObj.gameObject.GetComponent <MeshRenderer>().material.mainTexture = brickTex; } } LookingObj = collider; if (LookingObj.name == "Brick(Clone)") { LookingObj.gameObject.GetComponent <MeshRenderer>().material.mainTexture = ballTex; } Bar.Reset(); } else { Bar.IncreastTime(Time.deltaTime); } } else { if (LookingObj != null) { var particle = LookingObj.GetComponent <ParticleSystem>(); if (particle != null) { particle.Stop(); } if (LookingObj.name == "Brick(Clone)") { LookingObj.gameObject.GetComponent <MeshRenderer>().material.mainTexture = brickTex; } } Bar.Reset(); if (Mathf.Abs(Camera.transform.forward.x) < 0.1 && (Mathf.Abs(Camera.transform.forward.z) < 0.1) && towerHasBeenTouched && test) { foreach (var brick in tower) { Destroy(brick); } tower = new List <GameObject>(); towerHasBeenTouched = false; needRebuild = true; } } }