Death
How do I use Death
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
56 | public void PlayerDeath(){ | 1 |
94 | MusicController.instance.PlayerDeath (); | 2 |
60 | Death (); | 3 |
71 | void Death(){ | 4 |
90 | if (collision.tag == "Death") { | 5 |
File name: MusicController.cs
Copy
56 public void PlayerDeath(){
57 if(explode){
58 audioSource.PlayOneShot (explode);
59 }
60 }
File name: PlayerController.cs
Copy
91 public void PlayerDied(){
92 if(GameController.instance != null && MusicController.instance != null){
93 if(GameController.instance.isMusicOn){
94 MusicController.instance.PlayerDeath ();
95 }
96 }
97 Instantiate (explosion, transform.position, Quaternion.identity);
98 Destroy (gameObject);
99 GameplayController.instance.GameOver ();
100 }
File name: EnemyController.cs
Copy
43 void OnCollisionEnter2D(Collision2D collision){
44 if(collision.relativeVelocity.magnitude > damageCounter){
45 hitPoints -= Mathf.RoundToInt(collision.relativeVelocity.magnitude);
46 UpdateScoreStatus (Mathf.RoundToInt (collision.relativeVelocity.magnitude));
47 if(GameController.instance != null && MusicController.instance != null){
48 if(GameController.instance.isMusicOn){
49 if (gameObject != null) {
50 AudioSource.PlayClipAtPoint (hurt, transform.position);
51 }
52 }
53 }
54 }
55
56
57 UpdateAnimationState ();
58
59 if(hitPoints <= 0){
60 Death ();
61
62 if(collision.gameObject.CompareTag("Player Bullet")){
63 bounce = collision.transform.GetComponent
64 bounce.y = 0f;
65 collision.transform.GetComponent
66
67 }
68 }
69 }
File name: EnemyController.cs
Copy
71 void Death(){
72 Destroy (gameObject);
73 GameObject newDeathEffect = Instantiate (deathEffect, transform.position, Quaternion.identity) as GameObject;
74 Destroy (newDeathEffect, 3f);
75 if(GameController.instance != null){
76 GameController.instance.score += maxScore;
77 }
78 DisplayScore ();
79
80 }
File name: PlayerScript.cs
Copy
73 void OnTriggerEnter2D(Collider2D collision) {
74 if (collision.tag == "Destruction") {
75 Destroy(this.gameObject);
76 GameManager.instance.GameOver();
77 }
78
79 if (collision.tag == "Ring") {
80 audioSource.PlayOneShot(scoreClip);
81 GameObject imp = (GameObject)Instantiate(impact, transform.position, transform.rotation);
82 Destroy(imp, 1f);
83 ScoreCount.instance.CountScore(1);
84
85 if (ScoreCount.instance.countScore >= randSCore) {
86 ScaryPictures();
87 }
88 }
89
90 if (collision.tag == "Death") {
91 Destroy(this.gameObject);
92 GameManager.instance.GameOver();
93 }
94
95 if (collision.tag == "Ground") {
96 Destroy(this.gameObject);
97 GameObject explode = (GameObject) Instantiate(explosion, transform.position, transform.rotation);
98 Destroy(explode, 0.8f);
99 GameManager.instance.GameOver();
100 }
101
102 if (collision.tag == "RingGroup") {
103 Destroy(collision.gameObject);
104
105 }
106 }
Death 179 lượt xem
Gõ tìm kiếm nhanh...