Advertisement
CakeMeister

2d shooter UFO 1 phan 6

Jul 29th, 2017
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class ufo1 : MonoBehaviour {
  6.     public int health = 100;
  7.     public float timer = 1;
  8.     public Vector3 direction;
  9.     // Use this for initialization
  10.     void Start () {
  11.        
  12.     }
  13.    
  14.     // Update is called once per frame
  15.     void Update () {
  16.         timer += Time.deltaTime;
  17.  
  18.         if (health <= 0)
  19.             Destroy(this.gameObject);
  20.  
  21.         transform.Translate(direction * Time.deltaTime/0.4f);
  22.  
  23.         if (timer > 1)
  24.         {
  25.             timer = 0;
  26.             newposition();
  27.         }
  28.  
  29.     }
  30.  
  31.     void Damage(int dmg)
  32.     {
  33.         health -= dmg;
  34.     }
  35.     void newposition()
  36.     {
  37.         direction = new Vector3(Random.Range(-1f, 1f), Random.Range(-1f, 1f), 0);
  38.        
  39.     }
  40.  
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement