public CubeController DoPush(Vector3 dir) { CubeController didPush = null; Vector3 origin = m_Cube.transform.position; RaycastHit outHit = new RaycastHit(); if (Physics.Linecast(origin, origin + dir, out outHit)) { //if has any collision object, look for a CubeController its parent object, and then try to move it CubeController cube = outHit.collider.transform.GetComponentInParent <CubeController>(); if (cube != null) { if (cube.m_CanBePushed) { didPush = cube.DoMove(dir); } else if (!cube.m_PushCubeType.Equals(PushType.DontPushCubes)) { cube.DoPush(dir); } //if is not possible to move, then try to shake it if (!didPush) { cube.DoShake(); } } } return(didPush); }
public void Move(Vector3 direction) { //If there is no cube interaction, can move if (m_CubeMoving.Count == 0) { int countMovingCubes = 0; foreach (CubeController controller in m_CubeControllers) { if (controller.m_CanControl) { CubeController moved = controller.DoMove(direction); if (moved != null) { countMovingCubes++; } } } if (countMovingCubes > 0) { m_NumberOfMoves++; //Debug.Log("Number of moves: " + m_NumberOfMoves); } } }
//Remove the CubeController (that is Moving or Rolling) from the moving list public void UnregisterMove(CubeController controller) { m_CubeMoving.Remove(controller); //When the cube moving list count is zero, means there is no cubes moving if (m_CubeMoving.Count == 0) { InputManager.Instance.UnlockControls(); GameManager.Instance.CheckLevelCompletion(); } }
//Remove the CubeController (that is Moving or Rolling) from the moving list public void UnregisterMove(CubeController controller) { m_CubeMoving.Remove(controller); //When the cube moving list count is zero, means there is no cubes moving if (m_CubeMoving.Count == 0) { InputManager.Instance.UnlockControls(); GameManager.Instance.CheckLevelCompletion(); } }
public void DoPush(Vector3 dir) { if (m_CanPush) { Vector3 origin = m_Cube.transform.position; RaycastHit outHit = new RaycastHit(); if (Physics.Linecast(origin, origin + dir, out outHit)) { //if has any collision object, look for a CubeController its parent object, and then try to move it CubeController cube = outHit.collider.transform.GetComponentInParent <CubeController>(); if (cube != null) { cube.DoMove(dir); } } } }
public CubeController DoMove(Vector3 dir) { //If there is a neighbor cube in this direction (CheckCollisionRecursive != null) //and this neighbor was pushed (DoPush != null) //then this cube can move too if (CheckCollisionRecursive(m_Cube.transform, dir) != null) { bool didPush = false; if (m_PushCubeType.Equals(PushType.PushCubesWhenMove)) { CubeController pushedCube = DoPush(dir); didPush = pushedCube != null; } if (!didPush) { return(null); } } ResetPosition(); CubeManager.Instance.RegisterMove(this); switch (m_MoveType) { case MovementType.Roll: DoRoll(dir); break; case MovementType.Slide: DoSlide(dir); break; } return(this); }
Collider CheckCollisionRecursive(Transform cubeTransform, Vector3 dir) { Vector3 origin = cubeTransform.position; RaycastHit outHit; if (Physics.Linecast(origin, origin + dir, out outHit)) { CubeController cubeCollider = outHit.transform.gameObject.GetComponent <CubeController>(); if (cubeCollider != null && cubeCollider.m_CanBePushed) { return(CheckCollisionRecursive(cubeCollider.m_Cube.transform, dir)); } else { return(outHit.collider); } } else { return(null); } }
//Add the CubeController (that is Moving or Rolling) into the moving list public void RegisterMove(CubeController controller) { InputManager.Instance.LockControls(); m_CubeMoving.Add(controller); }
//Add the CubeController into the general list. The Cubes never are removed from the list. public void Register(CubeController controller) { controller.m_Cube.GetComponent<RubberEffect>().enabled = m_JellyEffectEnabled; m_CubeControllers.Add(controller); }
//Add the CubeController (that is Moving or Rolling) into the moving list public void RegisterMove(CubeController controller) { InputManager.Instance.LockControls(); m_CubeMoving.Add(controller); }
//Add the CubeController into the general list. The Cubes never are removed from the list. public void Register(CubeController controller) { controller.m_Cube.GetComponent <RubberEffect>().enabled = m_JellyEffectEnabled; m_CubeControllers.Add(controller); }