Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- public class Gear : MonoBehaviour
- {
- public int damage = 1;
- public float speed;
- public GameObject effect;
- public GameObject sound;
- public GameObject sounddead;
- private Animator camAnim;
- private void Start()
- {
- camAnim = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Animator>();
- }
- private void Update()
- {
- transform.Translate(Vector2.left * speed * Time.deltaTime);
- }
- private void OnTriggerEnter2D(Collider2D other)
- {
- if (other.CompareTag("Player"))
- {
- if (other.GetComponent<Player>().health <= 1)
- {
- camAnim.SetTrigger("shake");
- Instantiate(sounddead, transform.position, Quaternion.identity);
- }
- else
- camAnim.SetTrigger("shake");
- Instantiate(sound, transform.position, Quaternion.identity);
- Instantiate(effect, transform.position, Quaternion.identity);
- other.GetComponent<Player>().health -= damage;
- Destroy(gameObject);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement