public void PushShell(ShellController shellController) { shellController.transform.parent = transform; Vector3 newShellPosition = transform.position; newShellPosition.z = shellController.transform.position.z; newShellPosition.y -= GetComponent <SpriteRenderer>().bounds.size.y; newShellPosition.y += shellController.GetComponent <SpriteRenderer>().bounds.size.y / 2; int pushNumber = GetComponentsInChildren <ShellController>().Length; float horizontalOffset = 0; switch (pushNumber) { case 2: horizontalOffset = -shellController.GetComponent <SpriteRenderer>().bounds.size.x / 2; break; case 3: horizontalOffset = shellController.GetComponent <SpriteRenderer>().bounds.size.x / 2; break; case 4: horizontalOffset = shellController.GetComponent <SpriteRenderer>().bounds.size.x / 4; break; } newShellPosition.x += horizontalOffset; shellController.transform.position = newShellPosition; }
public void OnShellDrop(ShellController shellController) { bool shellPushed = false; foreach (var tray in trays) { if (tray.GetComponent <Collider2D>().bounds.Intersects(shellController.GetComponent <Collider2D>().bounds)) { tray.PushShell(shellController); shellPushed = true; } } if (!shellPushed) { shellController.PushTable(); } }
public void OnShellDrag(ShellController shellController) { }