SizilStank

Untitled

May 3rd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PowerUps : MonoBehaviour
  6. {
  7.     [SerializeField] int _powerUpID; // 0 = slow game speed, 1 = fast game speed.
  8.     [SerializeField] private float _speed = 5.0f;
  9.  
  10.  
  11.  
  12.     // Update is called once per frame
  13.     void Update()
  14.     {
  15.         transform.Translate(Vector3.down * _speed * Time.deltaTime);
  16.  
  17.         if (transform.position.y < -1)
  18.         {
  19.             Destroy(this.gameObject);
  20.         }
  21.     }
  22.  
  23.  
  24.     private void OnTriggerEnter2D(Collider2D collision)
  25.     {
  26.         Debug.Log("Hit " + collision.name);
  27.  
  28.         if (collision.tag == "Ball")
  29.         {
  30.             Ball ball = collision.GetComponent<Ball>();      
  31.  
  32.             if (ball != null)
  33.             {
  34.                 if (_powerUpID == 0)
  35.                 {
  36.                     Debug.Log("Hit ID 0");
  37.                     ball.CanGameSlowOn();
  38.                 }
  39.                 else if (_powerUpID == 1)
  40.                 {
  41.                     Debug.Log("Hit ID 1");
  42.                     ball.CanGameFastOn();
  43.                 }
  44.  
  45.             }
  46.  
  47.             Destroy(this.gameObject);
  48.            
  49.         }
  50.     }
  51.  
  52.  
  53.  
  54.  
  55.  
  56. }
Add Comment
Please, Sign In to add comment