void Start() { GameObject.Destroy(this.gameObject, LifeTime); // Shaking a camera ShakeCamera.Shake(0.2f, 0.7f); }
public void DoDamage() { var explosionPos = transform.position; var colliders = Physics.OverlapSphere(explosionPos, Radius); foreach (var hit in colliders) { if (!hit || hit.gameObject == this.gameObject || hit.gameObject.tag == this.gameObject.tag) { continue; } if (listObjHitted.Contains(hit.gameObject)) { continue; } var dir = (hit.transform.position - transform.position).normalized; var direction = Vector3.Dot(dir, transform.forward); if (direction < Direction) // Only hit an object in the direction. { continue; } var orbit = Camera.main.gameObject.GetComponent <OrbitGameObject>(); if (orbit != null && orbit.Target == hit.gameObject) { ShakeCamera.Shake(0.5f, 0.5f); } var dirforce = (this.transform.forward + transform.up) * Force; if (hit.gameObject.GetComponent <CharacterStatus>()) { if (SoundHit.Length > 0) { int randomindex = Random.Range(0, SoundHit.Length); if (SoundHit[randomindex] != null) { AudioSource.PlayClipAtPoint(SoundHit[randomindex], this.transform.position); } } int damage = this.gameObject.GetComponent <CharacterStatus>().Damage; int damageCal = (int)Random.Range(damage / 2.0f, damage) + 1; var status = hit.gameObject.GetComponent <CharacterStatus>(); int takedamage = status.ApplayDamage(damageCal, dirforce); // Add Particle Effect AddFloatingText(hit.transform.position + Vector3.up, takedamage.ToString()); status.AddParticle(hit.transform.position + Vector3.up); } if (hit.GetComponent <Rigidbody>()) { // push rigidbody object hit.GetComponent <Rigidbody>().AddForce(dirforce); } // add this object to the list. We wont make a multiple hit in the same object AddObjHitted(hit.gameObject); } }
/// <summary> /// This method is run when the number of lives decreases /// </summary> /// <param name="message"></param> /// <returns></returns> public override bool RunMethod(LivesChangedMessage message) { if (message.NewLives < message.OldLives) { ShakeCamera.Shake(); } return(true); }
void OnTriggerEnter2D(Collider2D other) { if (other.tag == "EnemyShotP" && this.tag == "MagicCircleP") { Destroy(other.gameObject); Destroy(gameObject); if (magicCircleScript.InstansMagicCircle.Count != 0) { magicCircleScript.InstansMagicCircle.RemoveAt(0); } } else if (other.tag == "EnemyShotG" && this.tag == "MagicCircleG") { Destroy(other.gameObject); Destroy(gameObject); if (magicCircleScript.InstansMagicCircle.Count != 0) { magicCircleScript.InstansMagicCircle.RemoveAt(0); } } else if (other.tag == "EnemyShotP" && this.tag == "MagicCircleG") { Destroy(other.gameObject); Destroy(gameObject); magicCircleScript.Canshot(); shakeCamera.Shake(0.25f, 2f); foreach (GameObject obj in magicCircleScript.InstansMagicCircle) { Destroy(obj); } magicCircleScript.InstansMagicCircle.Clear(); } else if (other.tag == "EnemyShotG" && this.tag == "MagicCircleP") { Destroy(other.gameObject); Destroy(gameObject); magicCircleScript.Canshot(); shakeCamera.Shake(0.25f, 2f); foreach (GameObject obj in magicCircleScript.InstansMagicCircle) { Destroy(obj); } magicCircleScript.InstansMagicCircle.Clear(); } }
void Die() { isDead = true; camShaker.Shake(); StartCoroutine("DisableCollider"); scoreText.text = score.ToString(); sfx.PlayOneShot(sfxList[2]); Debug.Log("Score: " + score); HighScore(); }
//public virtual void OnCollisionEnter(Collision collision) //{ // if (collision.gameObject.layer == LayerMask.NameToLayer("Player")) // { // collision.gameObject.GetComponent<Health>().SetDamages(damages); // } //} private void OnTriggerEnter(Collider other) { if (other.gameObject.layer == LayerMask.NameToLayer("Player")) { other.gameObject.GetComponent <Health>().SetDamages(damages); StartCoroutine(shakecam.Shake(1f, 0.2f)); StartCoroutine(Explosion(other.gameObject.transform.position)); Destroy(gameObject); } }
private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.name == "Player" && gameObject.name != "Dreadnaught") { KillEnemy(); //gameObject.GetComponent<ShakeCamera>().Shake(); ShakeCamera camShake = gameObject.AddComponent <ShakeCamera>(); camShake.Shake(); collision.collider.GetComponent <Player>().TakeDamage(); } }
public virtual void OnCollisionEnter(Collision collision) { if (collision.gameObject.layer == LayerMask.NameToLayer("Player")) { anima.SetTrigger("Attac"); forBlood.BloodParticles(); forBlood.degatAnim(); collision.gameObject.GetComponent <Health>().SetDamages(damages); StartCoroutine(shakecam.Shake(1f, 0.2f)); agent.isStopped = true; Invoke("FollowingAgain", 1.5f); } }
void OnTriggerEnter(Collider collider) { if (collider.gameObject.name == "Missile(Clone)") { shaker.Shake(); Explode(); damage += damagePercentage; status.text = damage.ToString() + "%"; if (100 <= damage) { Time.timeScale = 0; gameOverMsg.text = string.Format("Game Over!\nScore: {0}!", obsCount); } } }
void OnCollisionEnter(Collision other) { if (other.gameObject.tag == "Obstacle") { // When the player is destroyed it falls through the ground after its movement is disabled //gameObject.GetComponent<BoxCollider>().enabled = false; //movement.enabled = false; //cameraFollow.enabled = false; Destroy(gameObject, 1f); score.alive = false; gameManager.EndGame(); StartCoroutine(cameraShake.Shake(.15f, .4f)); } }
void OnCollisionEnter2D(Collision2D col) { if (col.gameObject.tag == "ally") { col.gameObject.GetComponent <Blue>().TakeDmg(); DieLie(); } else if (col.gameObject.tag == "ground") { if (stage != MOVE_STAGE.jump) { return; } // lấy vector pháp tuyến của bề mặt Vector3 normal = col.contacts[0].normal; //Debug.Log("normal: " + normal); // nếu vector pháp tuyến chỉ lên trên -> đáp đất if (normal.y > 0) { stage = MOVE_STAGE.run; animator.Play("run", -1, 0.0f); headAnim.Play("head_ready", -1, 0.0f); legAnim.Play("foot_ready", -1, 0.0f); jumpLevel = 0; // reset thoi gian phat am thanh audio.clip = clipStep1; audio.Play(); timer = stepTime; } if (normal.x < -0.5) // thêm if này mới toàn vẹn { audio.clip = clipBump; audio.Play(); rigid.velocity = new Vector3(-10.0f, 10.0f); TouchWall(); // rung camera ShakeCamera.Shake(); } } }
// Update is called once per frame void Update() { RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, transform.up, range, whatIsSolid); if (hitInfo.collider != null) { if (hitInfo.collider.CompareTag("Player")) { hitInfo.collider.GetComponent <Player>().TakeDamage(); ShakeCamera camShake = gameObject.AddComponent <ShakeCamera>(); camShake.Shake(); } DestroyMissile(); } transform.Translate(Vector2.up * speed * Time.deltaTime); }
/// <summary> /// Invoke a camera effect by index. The feature camera list will be used to locate the actual camera setting: fov, rotation, etc. /// </summary> /// <param name="index"></param> private void StartCameraEffect(int index, EnumShakeEffect shakeEffect = EnumShakeEffect.none, bool forceHold = false) { SkillCamera cam = null; if (index >= 0) { cam = skillCameraList._skillCameraList [index]; Debug.Log("Starting camera effect: " + index + " Name: " + cam.cameraName); _shakeCamera.StopShake(); SetSkillCamera(cam, forceHold); } if (shakeEffect != EnumShakeEffect.none) { _shakeCamera.Shake(shakeEffect.ToString(), shakeEffect == EnumShakeEffect.shake3_loop ? -1f : 0.4f, 1.0f); } }
public void EnemyCollision() { #if UNITY_EDITOR DisplayDebugMessage("Collided with enemy."); #endif if (!PlayerManager.canBeDamaged) { return; } cameraShake.Shake(); if (PlayerManager.shieldActive) { player.TakeHit(); audioManager.PlayShieldDepletedNoise(); return; } audioManager.PlayCrashNoise(); GameOver(); }
void ShakeScreen() { ShakeCamera.Shake(); Invoke("HideBabyDown", 2); }
// 当たった時に呼ばれる関数 void OnTriggerEnter(Collider other) { Debug.Log("なにかが斧に触れました"); Debug.Log("触れたオブジェクトのタグは" + other.gameObject.tag); // オブジェクトからTextコンポーネントを取得 Text score_text_body = score_object_body.GetComponent <Text>(); Text score_text_title = score_object_title.GetComponent <Text>(); // テキストの表示を替える score_text_body.text = "タグは" + other.gameObject.tag; score_text_title.text = j + "回目の木"; if (other.gameObject.tag == "flag" && flag == false) { flag = true; } if (other.gameObject.tag == "Tree") { //斧が木に触れたときに呼び出される //play sound effect GetComponent <AudioSource>().Play(); // 効果音を //.....処理 audioSource = gameObject.GetComponent <AudioSource>(); audioSource.clip = audioClip2; audioSource.Play(); //Debug.Log("木に触れたよ!!"); //hitpos = other.ClosestPointOnBounds(this.transform.position); //hitpos = axe.transform.position; hitpos = this.transform.position; emitParams.position = hitpos; Debug.Log("hitPos" + hitpos); //ここでパーティクルを発生させる Invoke("DoEmit", 0f); //一回目のヒット時に当たった場所に傷の位置をもってくる if (k == 0) { float positionDamage; hitpos_axetip = axeTip.transform.position; positionDamage = hitpos_axetip.y; Debug.Log("斧の先端の位置は" + hitpos_axetip.y); parent2.gameObject.transform.Translate(0, positionDamage - 0.737f - 0.30f, 0); k++; } } if (other.gameObject.tag == "Damage" && flag == true) { if (j < 5) { Debug.Log("------------------ダメージに" + (j + 1) + "ヒット目-------------------"); unitychan = parent2; //Unityちゃんをオブジェクトの名前から取得して変数に格納する Debug.Log(other + "に当たりました"); script = unitychan.GetComponent <ShakeCamera>(); //unitychanの中にあるUnityChanScriptを取 if (k != 0) { script.Shake(); //UnityChanScriptにある関数Attackを実行する } //斧が木に触れたときに呼び出される //play sound effect //GetComponent<AudioSource>().Play(); // 効果音を audioSource = gameObject.GetComponent <AudioSource>(); audioSource.clip = audioClip2; audioSource.Play(); //.....処理 //Debug.Log("木に触れたよ!!"); //hitpos = other.ClosestPointOnBounds(this.transform.position); //hitpos = this.transform.position; hitpos = this.transform.position; emitParams.position = hitpos; Debug.Log("hitPos" + hitpos); //ここでパーティクルを発生させる Invoke("DoEmit", 0f); //次の木のobjectを有効にする botd_objects[j + 1].gameObject.SetActive(true); //今の木のobjectを無効にする botd_objects[j].gameObject.SetActive(false); //最後の木なら終了のメッセージを出す if (TREES_TAGS.Length - 2 == j) { finishMessage.gameObject.SetActive(true); } flag = false; j++; } else { Debug.Log("over!"); } } }