public void OnTriggerExit2D(Collider2D other) { SideScrollingPlayer player = other.GetComponent <SideScrollingPlayer> (); if (player != null) { downObj.gameObject.SetActive(false); upObj.gameObject.SetActive(false); } }
public void OnTriggerEnter2D(Collider2D other) { SideScrollingPlayer player = other.GetComponent <SideScrollingPlayer> (); if (player != null) { this.player = player; downObj.gameObject.SetActive(down); upObj.gameObject.SetActive(up); } }
void OnTriggerExit2D(Collider2D col) { SideScrollingPlayer player = col.GetComponent <SideScrollingPlayer> (); if (player != null) { player.ToggleAbilityControl(); exitUI.SetActive(false); canLeave = false; } }
// Use this for initialization void Start() { target = FindObjectOfType <SideScrollingPlayer>(); roomManager = FindObjectOfType <RoomManager>(); }
// Use this for initialization void Start() { canLeave = false; player = FindObjectOfType <SideScrollingPlayer> (); }
void CameraUpdate() { if (pause) { pause = false; } else if (!revealing) { // Calculate the ideal camera size for this room float roomWidth = roomSizeMax.x - roomSizeMin.x; float roomHeight = roomSizeMax.y - roomSizeMin.y; // Ensure camera doesn't get bigger or smaller than its min and max bounds if (roomWidth > cameraMaxWidth) { roomWidth = cameraMaxWidth; } else if (roomWidth < cameraMinWidth) { roomWidth = cameraMinWidth; } if (roomHeight > cameraMaxHeight) { roomHeight = cameraMaxHeight; } else if (roomHeight < cameraMinHeight) { roomHeight = cameraMinHeight; } // If aspect ratio on ideal room size doesn't match the current aspect ratio, change width or height to make it match float aspect = cam.aspect; // If width is too big, lower it to be in line with aspect ration if (roomWidth / roomHeight > aspect) { roomWidth = roomHeight * aspect; } // If height is too big, lower it to be in line with aspect ratio else if (roomWidth / roomHeight < aspect) { roomHeight = roomWidth / aspect; } // Set camera size gradually // If camera needs to be bigger, boost it up if (cam.orthographicSize < roomHeight / 2.0f) { cam.orthographicSize += cameraScaleSpeed; } // If cam needs to be smaller, scale it down else if (cam.orthographicSize > roomHeight / 2.0f) { cam.orthographicSize -= cameraScaleSpeed; } // If the camera is close enough to the right size, jump it there if (Mathf.Abs(cam.orthographicSize - (roomHeight / 2.0f)) < cameraScaleSpeed) { cam.orthographicSize = roomHeight / 2.0f; } float cameraHeight = cam.orthographicSize * 2.0f; float cameraWidth = cameraHeight * cam.aspect; // Calculate the camera position in this room Vector3 playerPosition = player.transform.position; Vector3 cameraPosition = new Vector3(playerPosition.x, playerPosition.y, transform.position.z); // Here we clamp the desired position into the area declared in the limit variables. if (limitCamXMovement) { cameraPosition.x = Mathf.Clamp(cameraPosition.x, roomSizeMin.x + cameraWidth / 2.0f, roomSizeMax.x - cameraWidth / 2.0f); } if (limitCamYMovement) { cameraPosition.y = Mathf.Clamp(cameraPosition.y, roomSizeMin.y + cameraHeight / 2.0f, roomSizeMax.y - cameraHeight / 2.0f); } // and now we're updating the camera position using what came of all the calculations above. if (waitToCenter && this.transform.position == cameraPosition) { waitToCenter = false; SideScrollingPlayer playerCont = player.GetComponent <SideScrollingPlayer> (); if (playerCont) { playerCont.RevealDone(); } } this.transform.position = Vector3.MoveTowards(transform.position, cameraPosition, cameraMoveSpeed); } else { if (revPoints.Count != 0) { if (this.transform.position.x == revPoints [0].x && this.transform.position.y == revPoints[0].y) { revPoints.Remove(revPoints [0]); pause = true; } else { this.transform.position = Vector3.MoveTowards(this.transform.position, new Vector3(revPoints [0].x, revPoints [0].y, this.transform.position.z), cameraMoveSpeed); } } else { revealing = false; waitToCenter = true; } } }