Advertisement
Guest User

Untitled

a guest
Jan 1st, 2021
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6.  
  7. public class Gear : MonoBehaviour
  8. {
  9. public int damage = 1;
  10. public float speed;
  11.  
  12. public GameObject effect;
  13. public GameObject sound;
  14. public GameObject sounddead;
  15.  
  16. private Animator camAnim;
  17.  
  18. private void Start()
  19. {
  20. camAnim = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Animator>();
  21. }
  22.  
  23. private void Update()
  24. {
  25. transform.Translate(Vector2.left * speed * Time.deltaTime);
  26. }
  27.  
  28. private void OnTriggerEnter2D(Collider2D other)
  29. {
  30. if (other.CompareTag("Player"))
  31. {
  32. if (other.GetComponent<Player>().health <= 1)
  33. {
  34. camAnim.SetTrigger("shake");
  35. Instantiate(sounddead, transform.position, Quaternion.identity);
  36. }
  37. else
  38. camAnim.SetTrigger("shake");
  39. Instantiate(sound, transform.position, Quaternion.identity);
  40. Instantiate(effect, transform.position, Quaternion.identity);
  41. other.GetComponent<Player>().health -= damage;
  42. Destroy(gameObject);
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement