void Start() { if (mainMusic) { audioPlayer.PlaySound(mainMusic); } if (ambientMusic) { audioPlayer.PlaySound(ambientMusic); } }
void Update() { if (velocity.y < -14 && controller.collisions.below) { Debug.Log("Pong"); animator.SetBool("isJumping", false); animator.SetTrigger("triggerBounce"); impulseSource.GenerateImpulse(velocity); audioPlayer.PlaySound(playerLanding); } if (controller.collisions.above || controller.collisions.below) { velocity.y = 0; if (controller.collisions.below) { currentJump = 0; animator.SetBool("isJumping", false); } } Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); if (Input.GetButtonDown("Jump") && (controller.collisions.below || currentJump < maxJumps)) { currentJump += 1; velocity.y = maxJumpVelocity; animator.SetBool("isJumping", true); } if (Input.GetButtonUp("Jump")) { if (velocity.y > minJumpVelocity) { velocity.y = minJumpVelocity; } } float targetVelocityX = input.x * moveSpeed; if (input.x != 0) { animator.SetBool("isRunning", true); if (input.x < 0) { sr.flipX = true; } else { sr.flipX = false; } } else { animator.SetBool("isRunning", false); } velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, (controller.collisions.below) ? accelerationTimeGrounded : accelerationTimeAirborne); velocity.y += gravity * Time.deltaTime; controller.Move(velocity * Time.deltaTime); }
public void OpenDialogBox() { isSwitchedOn = !isSwitchedOn; UpdateSprite(); audioPlayer.PlaySound(leverSound); dialogTrigger.TriggerDialogue(); }
public void PressPlate() { isSwitchedOn = !isSwitchedOn; UpdateSprite(); //Switch levers foreach (LeveredDoor door in doorList) { door.SwitchOpenClose(); } audioPlayer.PlaySound(leverSound); }
private void OnTriggerEnter2D(Collider2D collision) { Player player = collision.GetComponent <Player>(); if (player) { audioPlayer.PlaySound(endLevel); float totalWaitTime = endLevel.clip.length + timeBeforeStartNextLevel; player.AddCooldown(totalWaitTime); Invoke("NextLevel", totalWaitTime); } }
private void OnTriggerEnter2D(Collider2D collision) { Player player = collision.GetComponent <Player>(); if (player) { audioPlayer.PlaySound(toPlayOnPickup, onEndPlay: () => Destroy(gameObject) ); toIncreaseOnPickup.Value++; //Hide the sprite once picked up gameObject.GetComponent <SpriteRenderer>().enabled = false; //Disable the collider once picked up gameObject.GetComponent <Collider2D>().enabled = false; } }
private void ShootAt(Vector3 worldPos) { RotateToward(worldPos); Bullet bullet = Instantiate(bulletPrefab, transform.position, Quaternion.identity, MapManager.Instance.BulletParent) .GetComponent <Bullet>(); Vector3 direction = (worldPos - transform.position).normalized; bullet.Direction = direction; bullet.Source = this; bullet.SetVelocityAndDamage(projectileSpeed, damage); bullet.gameObject.SetActive(true); shootCooldown = 1f / rateOfFire; player.PlaySound("son_tir"); }
public IEnumerator Teleport(Player player, float teleportationTime) { //If the teleporter is in use, abort if (isTeleporting) { yield break; } //We wait for any other movement coroutines to finish before starting this one. while (player.IsMoving) { yield return(null); } //we prevent the player from moving while teleporting player.AddCooldown(teleportationTime); //Staircase sound! audioPlayer.PlaySound(staircaseSound); //We set both teleporters as "In Use" isTeleporting = true; exitPassage.isTeleporting = true; //Fade the player to transparency yield return(StartCoroutine(player.FadePlayerTo(0f, teleportationTime / 2f))); //Teleport! player.transform.position = exitPassage.transform.position; //Fade them back to reality yield return(StartCoroutine(player.FadePlayerTo(1f, teleportationTime / 2f))); // Player can move again player.SetMoveStatus(true); //We set both teleporter as "Available" isTeleporting = false; exitPassage.isTeleporting = false; }
public IEnumerator Teleport(Player player, float teleportationTime) { //If the teleporter is in use, abort if (isTeleporting) { yield break; } //We wait for any other movement coroutines to finish before starting this one. while (player.IsMoving) { yield return(null); } //we prevent the player from moving while teleporting player.AddCooldown(teleportationTime); //Staircase sound! audioPlayer.PlaySound(teleportSound); //We set both teleporters as "In Use" isTeleporting = true; // exitPortal.isTeleporting = true; //Fade the player to transparency yield return(StartCoroutine(player.FadePlayerTo(0f, teleportationTime / 2f))); //Teleport! SceneManager.LoadSceneAsync("TestLevel2"); //Fade them back to reality yield return(StartCoroutine(player.FadePlayerTo(1f, teleportationTime / 2f))); //We set both teleporter as "Available" isTeleporting = false; // exitPortal.isTeleporting = false; }
void OnMouseOverItem(Item item, SwipeDirection direction) { // If selected item is already select or player cannot play during animations, game setup, etc if (_selectedItem == item || !canPlay) { _selectedItem = null; // Unselect item SetSelectItems(false, item); // Remove select status from item return; } // If input is lesser then swipe threshold, we consider it as a "click" if (direction == SwipeDirection.None) { if (_selectedItem == null) { _selectedItem = item; // There is no other item selected, select this one SetSelectItems(true, item); // Update item select status audioPlayer.PlaySound(selectSFX); // Play sound } else { // We have 2 selected items Vector3 itemPos = new Vector3(item.x, item.y, 0); Vector3 selectedPos = new Vector3(_selectedItem.x, _selectedItem.y, 0); // Previously selected item // Check if selected is in permited radius (the neighbors always has distance 1) if ((itemPos - selectedPos).magnitude == 1) { // Try to swap items StartCoroutine(TryMatch(_selectedItem, item)); } else { Debug.Log("This move is forbidden."); } SetSelectItems(false, item, _selectedItem); // Set items select status to false _selectedItem = null; } } else { // Input is a swipe Item nextItem = null; if (direction == SwipeDirection.Up && item.y + 1 < height) { // If direction is up and in board size bounds, select upper item nextItem = _items[item.x, item.y + 1]; } else if (direction == SwipeDirection.Right && item.x + 1 < width) { // If direction is right and in board size bounds, select right item nextItem = _items[item.x + 1, item.y]; } else if (direction == SwipeDirection.Down && item.y - 1 >= 0) { // If direction is down and in board size bounds, select lower item nextItem = _items[item.x, item.y - 1]; } else if (direction == SwipeDirection.Left && item.x - 1 >= 0) { // If direction is left and in board size bounds, select left item nextItem = _items[item.x - 1, item.y]; } if (nextItem) { StartCoroutine(TryMatch(item, nextItem)); // Try a match } if (_selectedItem) { // Reset a previously selected item SetSelectItems(false, _selectedItem); // Set items select status to false _selectedItem = null; } } }
private void Open() { IsOpen = true; audioPlayer.PlaySound(openingDoor); }
private void Unlock() { IsOpen = true; audioPlayer.PlaySound(unlockingDoor); }
void Start() { audioPlayer.PlaySound(mainMusic); }
// Start is called before the first frame update void Start() { bouton.onClick.AddListener(() => player.PlaySound("buy_upgrade")); }
public void PlayGame() { audioPlayer.PlaySound(selectSFX); StartCoroutine(ChangeScene("Playground")); }