private void changeAsset(Direction direction) { //Play sound SoundsManager.PlaySound(SoundsManager.Sound.Moves); switch (direction) { default: case Direction.Up: snakeBody.SetFloat("Horizontal", 0); snakeBody.SetFloat("Vertical", 1); break; case Direction.Down: //Down snakeBody.SetFloat("Horizontal", 0); snakeBody.SetFloat("Vertical", -1); break; case Direction.Right: //Right snakeBody.SetFloat("Horizontal", 1); snakeBody.SetFloat("Vertical", 0); break; case Direction.Left: //Left snakeBody.SetFloat("Horizontal", -1); snakeBody.SetFloat("Vertical", 0); break; } }
IEnumerator Death() { //RemoveMonsterFromShootingList PlayerController playerController = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerController>(); playerController.shootTargets.Remove(this.transform); // yield return(new WaitForSeconds(0.07f)); rb = GetComponent <Rigidbody2D>(); rb.velocity = Vector3.zero; GetComponent <CircleCollider2D>().enabled = false; yield return(new WaitForSeconds(0.07f)); soundsManager.PlaySound("MonsterExplosion"); GameObject particle = GameObject.Instantiate(deathParticlePrefab); particle.transform.position = transform.position; coinsAverageSpawnNumber = coinsAverageSpawnNumber + Random.Range(-coinsRandomValue, coinsRandomValue); SpawnCoins(); targetFeedbackSprite.enabled = false; monsterSprite.DOFade(0, 0.03f); Destroy(particle, 1f); Destroy(this.gameObject, 1f); }
private void Show() { //Play sound SoundsManager.PlaySound(SoundsManager.Sound.gameOver); float score = GameHandler.GetScore() + ((float)GameHandler.GetScore() / GameHandler.GetTime()); //Load le score actuel transform.Find("TxtScoreObtained").GetComponent <Text>().text = "VOUS AVEZ EU " + (int)score + " POINTS"; //Donner le score Score.setScore((int)(GameHandler.GetScore() + ((float)GameHandler.GetScore() / GameHandler.GetTime()))); //Update le tableau Score.updateHighscore(); //Load le highscore string highscore = Score.GetHighScore().ToString(); for (int i = 1; i < 5; i++) { highscore += "\n" + Score.GetHighScore(i).ToString(); } transform.Find("TxtScore").GetComponent <Text>().text = highscore; string highscorePseudo = Score.GetHighScorePseudo().ToString(); for (int i = 1; i < 5; i++) { highscorePseudo += "\n" + Score.GetHighScorePseudo(i).ToString(); } transform.Find("TxtPseudo").GetComponent <Text>().text = highscorePseudo; gameObject.SetActive(true); }
public void Fire() { shotCD = Mathf.Clamp(shotCD, 0, fireRate); if (shotCD >= fireRate) { if (CrossPlatformInputManager.GetButton("Fire1")) { //Instantiate(playerBullet, firePoint.position, Quaternion.identity); GameObject bul = PlayerBulletPool.bulletPoolInstances.GetBullet(); bul.transform.position = firePoint.transform.position; bul.transform.rotation = Quaternion.Euler(0, 0, 0); bul.SetActive(true); shotCD -= shotCD; soundsManager.PlaySound(4); } } else if (shotCD < fireRate) { shotCD += Time.deltaTime; } }
public void PlayerShooting() { /** Key Actions**/ if (Input.GetKeyDown(KeyCode.F)) { Fire = true; GameObject bullet = Instantiate(bulletPref, bulletSpawner.position, bulletSpawner.rotation); bullet.GetComponent <Rigidbody2D> ().velocity = new Vector2(bulletSpeed, 2); if (playerT.localScale.x > 0) { bullet.GetComponent <Rigidbody2D> ().velocity = new Vector2(bulletSpeed, 2); transform.localScale = new Vector3(1f, 1f, 1f); } else { bullet.GetComponent <Rigidbody2D> ().velocity = new Vector2(-bulletSpeed, 2); transform.localScale = new Vector3(-1f, 1f, 1f); bullet.transform.localScale = new Vector3(-1f, 1f, 1f); } Destroy(bullet, 2.0f); } if (Input.GetKeyUp(KeyCode.F)) { Fire = false; SoundsManager.PlaySound("firePlayer"); //WinnerController.ActiveWin (true); } }
void Start() { soundsManager = FindObjectOfType <SoundsManager>(); playButton.GetComponent <Button_UI>().ClickFunc = () => { StartCoroutine(LoadGameScene()); }; playButton.MouseOverOnceFunc += () => { soundsManager.PlaySound(0); }; playButton.ClickFunc += () => { soundsManager.PlaySound(1); }; quitButton.GetComponent <Button_UI>().ClickFunc = () => { Application.Quit(); }; quitButton.MouseOverOnceFunc += () => { soundsManager.PlaySound(0); }; quitButton.ClickFunc += () => { soundsManager.PlaySound(3); }; }
IEnumerator BuyJingle() { audioMixer.DOSetFloat("MusicVolume", -30, 0.5f); soundsManager.PlaySound("BuyNewOutfit"); yield return(new WaitForSeconds(2.5f)); audioMixer.DOSetFloat("MusicVolume", -5, 1f); }
//Dame khi dính Spike public void Damage(int dmg) { SoundsManager.PlaySound("Hurt"); curHeath -= dmg; // animation trigger Hurt khi player gap phai spikes anim.SetTrigger("Hurt"); }
void Start() { soundsManager = FindObjectOfType <SoundsManager>(); retryButton.GetComponent <Button_UI>().ClickFunc = () => { StartCoroutine(LoadGameScene()); }; retryButton.MouseOverOnceFunc += () => { soundsManager.PlaySound(0); }; retryButton.ClickFunc += () => { soundsManager.PlaySound(1); }; menuButton.GetComponent <Button_UI>().ClickFunc = () => { StartCoroutine(LoadMenuScene()); }; menuButton.MouseOverOnceFunc += () => { soundsManager.PlaySound(0); }; menuButton.ClickFunc += () => { soundsManager.PlaySound(3); }; }
public void Damage(int damage) { curHealth -= damage; if (curHealth <= 0) { StartCoroutine(Die()); // hết máu sẽ bắt đầu chạy vòng lặp IEnumerator SoundsManager.PlaySound("Enemy Die"); } }
void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.tag == "Player") { GameObject thePlayer = GameObject.Find("Player"); MovementsPlayer Player = thePlayer.GetComponent <MovementsPlayer> (); SoundsManager.PlaySound("playerDying"); Player.Lifes = Player.Lifes - 1; } }
/** Jump One time**/ void Jump() { jump = true; if (jump) { rb2d.velocity = new Vector2(rb2d.velocity.x, 0); rb2d.AddForce(Vector2.up * jumpPower, ForceMode2D.Impulse); SoundsManager.PlaySound("donalJump"); jump = false; } }
void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.tag == "Player") { GameObject thePlayer = GameObject.Find("Player"); MovementsPlayer Player = thePlayer.GetComponent <MovementsPlayer> (); Player.diamantCount = Player.diamantCount + 1; SoundsManager.PlaySound("coin"); Destroy(gameObject); } }
/// <summary> /// shoot arrow /// </summary> public void Shoot() { if (_isCharged) { if (shootSound) { SoundsManager.PlaySound(shootSound); } else { Debug.LogWarning("ArrowShooter:Shoot() shootSound is not assigned."); } chargedArrow.Shoot(); _isCharged = false; Charge(); } }
void Shoot() { shootPosition = camera.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y)); soundsManager.PlaySound("Shoot"); if (shootTargets.Count != 0) { rb.velocity = Vector2.zero; //ChooseTarget Transform bestTarget = null; float closestDistanceSqr = Mathf.Infinity; foreach (Transform t in shootTargets) { Vector3 directionToTarget = t.position - transform.position; float dSqrToTarget = directionToTarget.sqrMagnitude; if (dSqrToTarget < closestDistanceSqr) { closestDistanceSqr = dSqrToTarget; bestTarget = t; } } shootDirection = -(new Vector2(bestTarget.position.x, bestTarget.position.y) - new Vector2(transform.position.x, transform.position.y)).normalized; } else { //shootDirection = -(shootPosition - new Vector2(transform.position.x, transform.position.y)).normalized; if (shootPosition.x >= 0) { shootDirection = new Vector2(-0.5f, 1); } else { shootDirection = new Vector2(0.5f, 1); } shoot = true; } gunAnimator.Play("Shoot"); CharaSpriteRotation(); GunSpriteRotation(); ShootAnim(); InstantiateBullets(bulletShootNumber, false); }
/** Enemy Shooting**/ public void Shooting() { GameObject bullet = Instantiate(bulletPref, bulletSpawner.position, bulletSpawner.rotation); bullet.GetComponent <Rigidbody2D> ().velocity = new Vector2(bulletSpeed, 3); if (playerT.localScale.x > 0) { bullet.GetComponent <Rigidbody2D> ().velocity = new Vector2(bulletSpeed, 3); transform.localScale = new Vector3(1f, 1f, 1f); } else { bullet.GetComponent <Rigidbody2D> ().velocity = new Vector2(-bulletSpeed, 3); transform.localScale = new Vector3(-1f, 1f, 1f); } SoundsManager.PlaySound("donalFire"); Destroy(bullet, 1.5f); }
/// <summary> /// set targeted to true, create flyingstar, play sound /// </summary> public virtual void Hit() { if (targeted || GameController.isGameDone) { return; } targeted = true; GameObject star = Instantiate(Resources.Load("UI/Star/Star"), transform.position, Quaternion.identity) as GameObject; if (hitSound) { SoundsManager.PlaySound(hitSound); } else { Debug.LogWarning("Target:Hit() hitSound is not assigned."); } }
IEnumerator OutfitReward(int index) { yield return(new WaitForSeconds(0.5f)); soundsManager.PlaySound("UnlockOutfit"); outfitsRewardsCanvas.gameObject.SetActive(true); outfitsRewardsCanvas.DOFade(1f, 0.2f); nameText.text = outfits[index].ToString().Replace("S_Outfit_", "").ToUpper(); characterImage.sprite = outfits[index]; //locked.transform.DOShakeScale(1, 0.4f, 90, 90); locked.gameObject.GetComponent <Animator>().enabled = true; yield return(new WaitForSeconds(1f)); locked.transform.localPosition = lockerPosition; locked.gameObject.SetActive(false); unlocked.gameObject.SetActive(true); unlocked.transform.DOScale(1, 0.3f); yield return(new WaitForSeconds(0.4f)); unlocked.DOFade(0, 0.5f); yield return(new WaitForSeconds(0.5f)); nameText.GetComponent <CanvasGroup>().DOFade(1, 0.5f); characterImage.DOFade(1, 0.5f); characterImage.transform.DOScale(1, 0.5f).SetEase(Ease.OutBounce); yield return(new WaitForSeconds(0.5f)); animator.enabled = true; exitButton.gameObject.SetActive(true); exitButton.DOFade(1, 0.3f); displayPopUp = false; }
// Update is called once per frame void FixedUpdate() { Vector3 fixedVelocity = rb2d.velocity; fixedVelocity.x *= 0.85f; // if (grounded) { rb2d.velocity = fixedVelocity; // } /*--Move to righ and left*/ float h = Input.GetAxis("Horizontal"); rb2d.AddForce(Vector2.right * speed * h); float limitedSpeed = Mathf.Clamp(rb2d.velocity.x, -maxSpeed, maxSpeed); rb2d.velocity = new Vector2(limitedSpeed, rb2d.velocity.y); if (h > 0.1f) { transform.localScale = new Vector3(1f, 1f, 1f); dir = 1; } if (h < -0.1f) { transform.localScale = new Vector3(-1f, 1f, 1f); dir = -1; } /*--Jump*/ if (Jump) { SoundsManager.PlaySound("jumpPlayer"); rb2d.velocity = new Vector2(rb2d.velocity.x, 0); rb2d.AddForce(Vector2.up * jumpPower, ForceMode2D.Impulse); Jump = false; } }
public void DestroyCoin() { StartCoroutine(AnimationCoin()); // Phương thức chạy vòng lặp Animationcoin và play sound SoundsManager.PlaySound("Coin"); }
//Animation leo thang public void Climb() //Phương thức được gọi bên script Ladder { anim.SetBool("IsClimb", true); //trạng thái va trạm vs Ladder SoundsManager.PlaySound("Climb"); }
void Update() { anim.SetBool("Grounded", grounded); anim.SetFloat("Speed", Mathf.Abs(Input.GetAxisRaw("Horizontal")) * speed); // kiem tra gia tri tang dan khi an ban phim cho animtor Run //xoay mặt player if (r2bd.velocity.x < -0.1f) { transform.localScale = new Vector3(-1, 1, 1); //quay mat sang ben trai } if (r2bd.velocity.x > 0.1f) //quay mat sang ben phai { transform.localScale = new Vector3(1, 1, 1); } //Jump & Double Jump if (Input.GetKeyDown(KeyCode.Space)) { if (canyouJump == true) { SoundsManager.PlaySound("Jumping"); countJump += 1; r2bd.AddForce(Vector2.up * jumpPower); anim.SetBool("IsJumping", true); if (countJump == 2) { anim.SetBool("IsJumping", false); anim.SetBool("IsFalling", false); anim.SetBool("DoubleJump", true); } } if (countJump == maxJump) { canyouJump = false; } } #region old animator Jump //if (r2bd.velocity.y == 0) //dung yen thi = 0 //{ // anim.SetBool("IsJumping", false); // anim.SetBool("IsFalling", false); // anim.SetBool("DoubleJump", false); //} //if ( && r2bd.velocity.y < 0) //{ // anim.SetBool("IsJumping", false); // anim.SetBool("IsFalling", true); //} //if (r2bd.velocity.y > 10) // chay lien tuc co the lam tang gia tri velocity //{ // anim.SetBool("IsJumping", true); //van toc cua y khi player nhay len se > 0 //} #endregion //Nhảy lần 1 và trong trạng thái đang rơi sẽ set trigger animation IsFalling if (countJump == 1 && r2bd.velocity.y < 0) { anim.SetBool("IsJumping", false); anim.SetBool("IsFalling", true); } //Trạng thái ấn button và nhả button sẽ set animation trigger Teleport if (Input.GetKeyDown(KeyCode.E)) { anim.SetBool("Teleport", true); SoundsManager.PlaySound("Teleport"); } if (Input.GetKeyUp(KeyCode.E)) { anim.SetBool("Teleport", false); } //Kiểm tra máu của nhân vật chỉ = maxHealth, nhỏ hơn 0 sẽ chạy phương thức Die if (curHeath > maxHealth) { curHeath = maxHealth; } if (curHeath <= 0) { Die(); } }
private void HandleGridMovement() { //Vitesse change if (snakeBodySize == 10) { coolDown = gridMoveTimerMax; gridMoveTimerMax = .15f; } if (snakeBodySize == 20) { coolDown = gridMoveTimerMax; gridMoveTimerMax = .1f; } if (snakeBodySize == 30) { coolDown = gridMoveTimerMax; gridMoveTimerMax = .06f; } gridMoveTimer += Time.deltaTime; if (gridMoveTimer >= gridMoveTimerMax) { gridMoveTimer -= gridMoveTimerMax; SnakeMovePosition snakeMovePosition = new SnakeMovePosition(gridPosition, gridMoveDirection); snakeMovePositionList.Insert(0, snakeMovePosition); Vector2Int gridMovePositionVector; switch (gridMoveDirection) { default: case Direction.Right: gridMovePositionVector = new Vector2Int(2, 0); break; case Direction.Left: gridMovePositionVector = new Vector2Int(-2, 0); break; case Direction.Up: gridMovePositionVector = new Vector2Int(0, 2); break; case Direction.Down: gridMovePositionVector = new Vector2Int(0, -2); break; } gridPosition += gridMovePositionVector; bool isDead = levelGrid.ValidatePosition(gridPosition, this); //Mort par touche de l'écran if (isDead) { state = State.Dead; GameHandler.SnakeDied(); } bool snakeAte = levelGrid.TryEatFood(gridPosition, inSpecialMode); if (snakeAte) { //Play sound SoundsManager.PlaySound(SoundsManager.Sound.gotEgg); snakeBodySize++; CreateSnakeBody(); } if (snakeMovePositionList.Count >= snakeBodySize + 1) { snakeMovePositionList.RemoveAt(snakeMovePositionList.Count - 1); } UpdateSnakeBodyParts(); //Mort par toucher la queue foreach (SnakeBodyPart snakeBodyPart in snakeBodyParts) { Vector2Int snakeBodyPartPosition = snakeBodyPart.GetPosition(); if (gridPosition == snakeBodyPartPosition) { state = State.Dead; GameHandler.SnakeDied(); } } transform.position = new Vector3(gridPosition.x, gridPosition.y, 0); } }
public void ClassicButtonSubmitSound() { soundsManager.PlaySound("ClassicButton"); }