Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PowerUps : MonoBehaviour
- {
- [SerializeField] int _powerUpID; // 0 = slow game speed, 1 = fast game speed.
- [SerializeField] private float _speed = 5.0f;
- // Update is called once per frame
- void Update()
- {
- transform.Translate(Vector3.down * _speed * Time.deltaTime);
- if (transform.position.y < -1)
- {
- Destroy(this.gameObject);
- }
- }
- private void OnTriggerEnter2D(Collider2D collision)
- {
- Debug.Log("Hit " + collision.name);
- if (collision.tag == "Ball")
- {
- Ball ball = collision.GetComponent<Ball>();
- if (ball != null)
- {
- if (_powerUpID == 0)
- {
- Debug.Log("Hit ID 0");
- ball.CanGameSlowOn();
- }
- else if (_powerUpID == 1)
- {
- Debug.Log("Hit ID 1");
- ball.CanGameFastOn();
- }
- }
- Destroy(this.gameObject);
- }
- }
- }
Add Comment
Please, Sign In to add comment