void CollisionForPushBox() { foreach (PhysicsComponent physicsEntity in m_PhysicsEntities) { foreach (PhysicsComponent other in m_PhysicsEntities) { if (physicsEntity == other) { continue; } BoxOverlap overlap = PhysicsUtility.GetOverlapOfBox(physicsEntity.PushBox, other.PushBox); if (PhysicsUtility.AreBoxesIntersecting(physicsEntity.PushBox, other.PushBox)) { physicsEntity.transform.Translate(new Vector3(overlap.x, 0) * 0.5f); other.transform.Translate(new Vector3(overlap.x, 0) * -0.5f); } return; } } }
// Update is called once per frame void Update() { const float X_SPEED = 10; if (gameObject.transform.localScale.x > 0) { gameObject.transform.Translate(-X_SPEED * Time.deltaTime, 0, 0); } else { gameObject.transform.Translate(X_SPEED * Time.deltaTime, 0, 0); } lifeTime -= Time.deltaTime; if (lifeTime <= 0) { Destroy(gameObject); } //火箭自己的B2D BoxCollider2D b2d = GetComponent <BoxCollider2D>(); foreach (var cur in vBox2D) { if (BoxOverlap.check(cur, b2d)) { //vBox2D.Remove(cur); Destroy(gameObject); Destroy(cur.gameObject); break; } } }
public BoxCast(Vector3 center, Vector3 halfExtents, Quaternion orientation, Vector3 direction, float distance, QueryFilter type) : base(type, direction, distance) { var box = new BoxOverlap(center, halfExtents, orientation, type); m_PrimaryShape = box; m_Points = box.Corners; InitPoints(); m_SecondaryShape = m_IsFiniteDistance ? new BoxOverlap(center + m_Direction * distance, halfExtents, orientation, type) : null; }
// Update is called once per frame void Update() { if (doorName != null) { //把主角放到門的位置 GameObject goDoor = GameObject.Find(doorName); if (goDoor != null) { gameObject.transform.position = goDoor.transform.position; } doorName = null; } if (Input.GetKeyDown(KeyCode.UpArrow)) { foreach (var goDoor in vDoor) { BoxCollider2D doorBox = goDoor.GetComponent <BoxCollider2D>(); BoxCollider2D heroBox = gameObject.GetComponent <BoxCollider2D>(); if (BoxOverlap.check(doorBox, heroBox)) { PhysicUnit.vLine.Clear(); //清除舊廠景的地板線條 doorName = goDoor.name; DoorInfo info = goDoor.GetComponent <DoorInfo>(); SceneManager.LoadScene(info.sceneName); vDoor.Clear(); //過場景時,將原場景的門清除 break; } } } //跳躍 if (Input.GetKeyDown(KeyCode.Space)) { physicUnit.jump(); } //左 if (Input.GetKey(KeyCode.LeftArrow)) { physicUnit.moveLeft(); } //右 if (Input.GetKey(KeyCode.RightArrow)) { physicUnit.moveRight(); } if (Input.GetKey(KeyCode.X)) { //載入prefab Object obj = Resources.Load <Object>("my_prefab/rocket"); GameObject newRocket = (GameObject)Instantiate <Object>(obj); newRocket.transform.position = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y + 0.5f, gameObject.transform.position.z); if (gameObject.transform.localScale.x > 0) { newRocket.transform.localScale *= -1; } } }