void Update() { if (isEnabledGameplay) { if (gc.GetIsGameplay() && box.GetComponent <BoxCollider2D>().enabled == false) //enables during gameplay { Debug.Log("Enabled trigger box"); box.GetComponent <BoxCollider2D>().enabled = true; } if (gc.GetIsBuilding() && box.GetComponent <BoxCollider2D>().enabled == true) //disabled during building { Debug.Log("Disabled trigger box"); box.GetComponent <BoxCollider2D>().enabled = false; } } if (!isEnabledGameplay) { if (isEnabledGameplay) { if (gc.GetIsGameplay() && box.GetComponent <BoxCollider2D>().enabled == true) //enables during gameplay { Debug.Log("Disabled trigger box"); box.GetComponent <BoxCollider2D>().enabled = false; } if (gc.GetIsBuilding() && box.GetComponent <BoxCollider2D>().enabled == false) //enabled during building { Debug.Log("Enabled trigger box"); box.GetComponent <BoxCollider2D>().enabled = true; } } } }
// Update is called once per frame void Update() { if (!gc.GetIsBuilding() && hasCollected) //disables object when collected { sprite.enabled = false; col.enabled = false; } else if (gc.GetIsBuilding()) //re-enables in the build screen { hasCollected = false; sprite.enabled = true; col.enabled = true; } }
private void OnCollisionEnter(Collision collision) { if (gc.GetIsBuilding()) { collision.gameObject.GetComponent <BaseObject>().Erase(); } }
void Update() { if (gc.GetIsBuilding() && thisSprite.color.a != defaultColour.a || hasFaded) //reset on build { thisSprite.color = defaultColour; box.enabled = true; hasFaded = false; } }
void Update() { thisPosition.x = transform.position.x; thisPosition.y = transform.position.y; if (thisPosition != build.GetPlayerSpawn()) { build.SetPlayerSpawn(thisPosition); } //hide any collisions/graphics if (!gc.GetIsBuilding()) { sprite.enabled = false; col.enabled = false; } else if (gc.GetIsBuilding()) { sprite.enabled = true; col.enabled = true; } }
void Update() { if (gc.GetIsGameplay() && !gc.GetIsPaused() && currentTimer <= 0.0f) { currentTimer = interval; Shoot(); } if (currentTimer > 0.0f) { currentTimer -= Time.deltaTime; } if (gc.GetIsBuilding()) { currentTimer = 0.0f; } }
void Update() { if (gc.GetIsGameplay()) //gameplay specific in here { if (!needReset) //allows for a reset when the player goes to gameplay { needReset = true; } if (build.GetPlayerSpawned() && needPlayer) //initialises the player this loop { Debug.Log("Initialising player(Platforming)"); player = FindObjectOfType <Player>(); needPlayer = false; } if (!hasInitialised) //initalises values for this script on play { player = null; timeLeft = build.GetTime(); timeText.text = "Time: " + timeLeft; coinText.text = "Coins: " + coins; scoreText.text = "Score: " + score; hasInitialised = true; } if (player == null) { player = FindObjectOfType <Player>(); } if (!gc.GetIsPaused()) { timeLeft -= Time.deltaTime; } roundedTime = Mathf.FloorToInt(timeLeft); if (player != null) { UpdateUI(); } if (timeLeft <= 0.0f) //boot to build if failed clear in time { gc.SetIsBuilding(true); } } if (gc.GetIsBuilding() && needReset) //resets, etc. here when entering building { ResetPlatformStats(); } }
void Update() { if (gc.GetIsGameplay() && needsEnable && !isDefeated && !gc.GetIsPaused()) { Debug.Log("Waking rigidbody"); rb.velocity = new Vector2(0, 0); currentTimer = 0.0f; rb.constraints = RigidbodyConstraints2D.None; anim.SetBool("isGameplay", true); needsEnable = false; } else if (gc.GetIsBuilding() && !needsEnable || gc.GetIsPaused() && !needsEnable || isDefeated) { Debug.Log("Sleeping rigidbody"); rb.constraints = RigidbodyConstraints2D.FreezePosition; needsEnable = true; anim.SetBool("isGameplay", false); rb.velocity = new Vector2(0, 0); isDefeated = false; currentTimer = 0.0f; this.transform.position = thisObject.GetDefaultPosition(); this.transform.rotation = Quaternion.Euler(0, 0, 0); } if (gc.GetIsGameplay() && !gc.GetIsPaused() && !isDefeated) { if (currentTimer <= 0.0f) { currentTimer = maxTimer; } if (currentTimer > 0.0f) { currentTimer -= Time.deltaTime; if (currentTimer <= 0.0f) { Debug.Log("Flipping"); Flip(); } } transform.Translate(Vector2.right * speed * Time.deltaTime); } }
void Update() { //come back to this when error text is enabled properly /*if (!gc.GetIsBuilding() && placedPlayer != maxPlayer) //player required first * { * errorText.text = "Need to place a player to play!"; * gc.SetIsBuilding(true); * } * if (!gc.GetIsBuilding() && placedExit != maxExit) //exit required next * { * errorText.text = "Need to place an exit to play!"; * gc.SetIsBuilding(true); * }*/ if (!gc.GetIsBuilding() && placedPlayer == maxPlayer && !GetPlayerSpawned()) //sets initial player spawn point { Vector3 tmp = new Vector3(playerSpawnPoint.x, playerSpawnPoint.y, 0); Instantiate(player, tmp, transform.rotation, gameObject.transform); playerSpawned = true; } if (gc.GetIsBuilding() && placedPlayer == maxPlayer && playerSpawnButton.enabled == true) { playerSpawnButton.enabled = false; } else if (gc.GetIsBuilding() && placedPlayer != maxPlayer && playerSpawnButton.enabled == false) { playerSpawnButton.enabled = true; } if (gc.GetIsBuilding() && placedExit == maxExit && exitButton.enabled == true) { exitButton.enabled = false; } else if (gc.GetIsBuilding() && placedExit != maxExit && exitButton.enabled == false) { exitButton.enabled = true; } if (gc.GetIsBuilding() && GetPlayerSpawned()) { Destroy(GameObject.Find("Player")); playerSpawned = false; } }
void Update() { if (!gc.GetIsBuilding() || gc.GetIsPaused() && heldID != 16) //sets the cursor to a null object while in gameplay or paused { SetHeldID(16); box.enabled = false; } if (gc.GetIsBuilding() && !gc.GetIsPaused() && heldID == 16) { SetHeldID(0); box.enabled = true; } if (heldID == 6) //base colour needed for green water { baseColour = new Color(0, 255, 0); } else if (heldID != 6) //every other object has white base colour { baseColour = Color.white; } if (heldID != 19) //only certain objects are scaled by 3x { if (heldID == 13 || heldID == 9 || heldID == 10 || heldID == 18) //player,etc. scaling { transform.localScale = new Vector3(3, 3, 3); box.size = boxSize; } else if (heldID != 13 && heldID != 9 && heldID != 10 && heldID != 18) { transform.localScale = new Vector3(1, 1, 1); box.size = boxSize; } } else if (heldID == 19 && transform.localScale != new Vector3(eraseScale, eraseScale, eraseScale)) //different while erasing { transform.localScale = new Vector3(eraseScale, eraseScale, eraseScale); } if (heldID == 9) //certain objects need rotating, eg. Fireball { transform.rotation = Quaternion.Euler(0, 0, 90); } else if (heldID != 9) //fireball only one rotated { transform.rotation = Quaternion.Euler(0, 0, 0); } if (currentBuildDelay > 0.0f) { currentBuildDelay -= Time.deltaTime; } if (currentBuildDelay <= 0.0f && isLocationValid) //prevents most duplicate placements { EnablePlacement(); } pointingLocation = Camera.main.ScreenToWorldPoint(Input.mousePosition); //keeps objects to a grid based system roundedLocation.x = Mathf.RoundToInt(pointingLocation.x); roundedLocation.y = Mathf.RoundToInt(pointingLocation.y); heldObject.sprite = placeableObjects[heldID].GetComponentInChildren <SpriteRenderer>().sprite; //displays sprite render to player this.transform.position = roundedLocation; if (!UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject()) { if (Input.GetMouseButton(0) && isLocationValid && gc.GetIsBuilding() && !gc.GetIsPaused()) { if (heldID != 19) { Instantiate(placeableObjects[heldID], new Vector3(roundedLocation.x, roundedLocation.y, 0), transform.rotation, parentObject.transform); DisablePlacement(); currentBuildDelay = buildDelay; if (heldID == 13 || heldID == 14) //reset to empty block after player is placed, prevents multiple spawns { SetHeldID(15); //allows player to specify next block } currentBuildDelay = buildDelay; } else { Debug.Log("Doing something else with left click"); } } } }
void Update() { if (gc.GetIsGameplay() && !initialFlip) { Debug.Log("Rotating initial"); FlipThis(); initialFlip = true; } if (isMoving && currentDelay > 0.0f) { isMoving = false; } if (currentDelay > 0.0f) { currentDelay -= Time.deltaTime; } if (currentDelay <= 0.0f && !gc.GetIsPaused()) { isMoving = true; } if (gc.GetIsBuilding()) { ResetThis(); } if (gc.GetIsPaused() && hasActivated) { isMoving = false; } if (!gc.GetIsPaused() && hasActivated) { if (!isMoving) { Debug.Log("Moving"); isMoving = true; } } if (gc.GetIsGameplay() && isMoving) //allows projectile to move at a static rate { rb.velocity = Vector3.zero; thisVelocity = rb.velocity; if (transform.position.y >= obj.GetDefaultPosition().y&& isFacingForward) //prevents spazzing while stopped { Debug.Log("Offset"); thisVelocity = Vector3.zero; hasReachedMax = true; didReachMax = true; } if (hasReachedMax == true) { Debug.Log("Reached Max"); FlipThis(); hasReachedMax = false; } if (isFacingForward) { tmp = 1; } else if (!isFacingForward) { tmp = -1; } thisVelocity.y = speed * tmp; } rb.velocity = thisVelocity; if (!isMoving) //stops object when not moving { rb.velocity = Vector3.zero; } }
void Update() { if (gc.GetIsGameplay()) { player = null; } //music switch if (gc.GetIsGameplay() && playMusic.mute == true) { buildMusic.mute = true; buildMusic.Stop(); playMusic.mute = false; playMusic.Play(); } if (gc.GetIsBuilding() && buildMusic.mute == true) { playMusic.mute = true; playMusic.Stop(); buildMusic.mute = false; buildMusic.Play(); } if (buildMusic.mute == false && buildMusic.volume != musicSlider.value) { buildMusic.volume = musicSlider.value; } if (playMusic.mute == false && playMusic.volume != musicSlider.value) { playMusic.volume = musicSlider.value; } //switching states of camera if (gc.GetIsGameplay() && isGameplay == false) { isGameplay = true; } if (!gc.GetIsGameplay() && isGameplay == true) { isGameplay = false; ResetPosition(); } if (player == null && isGameplay) { player = FindObjectOfType <Player>(); } if (isGameplay && player != null) //follows the payer location with a slight offset to allow for visibility { MoveToPlayer(); } if (isBoosting) { isBoosting = false; moveScale /= 2; } if (!isGameplay) //panning/button presses to change positions { if (Input.GetAxis("Boost") != 0) { isBoosting = true; moveScale *= 2; } if (Input.GetAxis("Horizontal") != 0) { if (Input.GetAxis("Horizontal") < 0) { transform.position += new Vector3(-1 * moveScale, 0, 0); } if (Input.GetAxis("Horizontal") > 0) { transform.position += new Vector3(1 * moveScale, 0, 0); } } if (Input.GetAxis("Vertical") != 0) { if (Input.GetAxis("Vertical") < 0) { transform.position += new Vector3(0, -1 * moveScale, 0); } if (Input.GetAxis("Vertical") > 0) { transform.position += new Vector3(0, 1 * moveScale, 0); } } } if (transform.position.x < 19.3f && !isGameplay) { transform.position = new Vector3(19.3f, transform.position.y, zOffset); } if (transform.position.x < 19.3f + xOffset && isGameplay) { transform.position = new Vector3(19.3f + xOffset, transform.position.y, zOffset); } if (transform.position.y < 10.5f) { transform.position = new Vector3(transform.position.x, 10.5f, zOffset); } }