SHARE
TWEET

Master 23 09

a guest Sep 23rd, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //bullet
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6. public class Bullet : MonoBehaviour
  7. {
  8.    
  9.     // Start is called before the first frame update
  10.     void Start()
  11.     {
  12.        
  13.     }
  14.  
  15.     // Update is called once per frame
  16.     void Update()
  17.     {
  18.        
  19.     }
  20.     private void OnCollisionEnter(Collision collision)
  21.     {
  22.         if (collision.gameObject.tag == "Emeny")
  23.         {
  24.             Destroy(collision.gameObject);
  25.         }
  26.         Destroy(gameObject);
  27.     }
  28. }
  29.  
  30. //enemy
  31. using System.Collections;
  32. using System.Collections.Generic;
  33. using UnityEngine;
  34.  
  35. public class Emeny : MonoBehaviour
  36. {
  37.     Vector3 direction;
  38.     public float s = 10f;
  39.     public GameObject player;
  40.     Rigidbody rb;
  41.     // Start is called before the first frame update
  42.     void Start()
  43.     {
  44.         player = GameObject.Find("Player");
  45.         rb = GetComponent<Rigidbody>();
  46.     }
  47.  
  48.     // Update is called once per frame
  49.     void Update()
  50.     {
  51.      
  52.         transform.LookAt(player.transform);
  53.  
  54.         Vector3 dir = player.transform.position - transform.position;
  55.  
  56.         direction = dir.normalized;
  57.  
  58.        
  59.     }
  60.     private void FixedUpdate()
  61.     {
  62.        
  63.         rb.AddForce(direction * s);
  64.        
  65.     }
  66.     private void OnCollisionEnter(Collision collision)
  67.     {
  68.         if (collision.gameObject.name == "Player")
  69.         {
  70.             Destroy(player.gameObject);
  71.         }
  72.     }
  73.    
  74. }
  75.  
  76. //player
  77. using System.Collections;
  78. using System.Collections.Generic;
  79. using UnityEngine;
  80.  
  81. public class Player : MonoBehaviour
  82. {
  83.     Rigidbody rb;
  84.     public float s = 10f;
  85.     public float bs = 100f;
  86.     public float score;
  87.     public float rs = 100f;
  88.     Vector3 v, r;
  89.     public float j = 0f;
  90.     public GameObject sp, bullet;
  91.     AudioSource audioSource;
  92.     // Start is called before the first frame update
  93.     void Start()
  94.     {
  95.         rb = GetComponent<Rigidbody>();
  96.         sp = GameObject.Find("BulletSpawn");
  97.         audioSource = GetComponent<AudioSource>();
  98.        
  99.        
  100.     }
  101.  
  102.     // Update is called once per frame
  103.     void Update()
  104.     {
  105.         float x = 0, y = 0, z = 0;
  106.        // float j = 0;
  107.         if (Input.GetKey(KeyCode.W))
  108.         {
  109.             z = 1;
  110.         }
  111.         if (Input.GetKey(KeyCode.S))
  112.         {
  113.             z = -1;
  114.         }
  115.         if (Input.GetKey(KeyCode.D))
  116.         {
  117.             y = 1;
  118.         }
  119.         if (Input.GetKey(KeyCode.A))
  120.         {
  121.             y = -1;
  122.         }
  123.         if (Input.GetKeyDown(KeyCode.Space))
  124.         {
  125.             audioSource.Play();
  126.             GameObject b = Instantiate(bullet, sp.transform.position, sp.transform.rotation);
  127.             Vector3 bsp = new Vector3(0, 0, 1) * bs;
  128.             b.GetComponent<Rigidbody>().AddRelativeForce(bsp);
  129.             Destroy(b, 3f);
  130.            
  131.         }
  132.       //  if (Input.GetKey(KeyCode.Space))
  133.       //  {
  134.       //      if (transform.position.y <= 0.55)
  135.       //      {
  136.       //          j = 20;
  137.       //          z += 1;
  138.  
  139.       //      }
  140.       //  }
  141.  
  142.         v = new Vector3(x, 0, z) * s;
  143.         r = new Vector3(0, y, 0) * rs;
  144.  
  145.  
  146.  
  147.     }
  148.     private void FixedUpdate()
  149.     {
  150.         rb.AddTorque(r);
  151.         rb.AddRelativeForce(v);
  152.  
  153.     }
  154. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top