Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //bullet
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Bullet : MonoBehaviour
- {
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- }
- private void OnCollisionEnter(Collision collision)
- {
- if (collision.gameObject.tag == "Emeny")
- {
- Destroy(collision.gameObject);
- }
- Destroy(gameObject);
- }
- }
- //enemy
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Emeny : MonoBehaviour
- {
- Vector3 direction;
- public float s = 10f;
- public GameObject player;
- Rigidbody rb;
- // Start is called before the first frame update
- void Start()
- {
- player = GameObject.Find("Player");
- rb = GetComponent<Rigidbody>();
- }
- // Update is called once per frame
- void Update()
- {
- transform.LookAt(player.transform);
- Vector3 dir = player.transform.position - transform.position;
- direction = dir.normalized;
- }
- private void FixedUpdate()
- {
- rb.AddForce(direction * s);
- }
- private void OnCollisionEnter(Collision collision)
- {
- if (collision.gameObject.name == "Player")
- {
- Destroy(player.gameObject);
- }
- }
- }
- //player
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Player : MonoBehaviour
- {
- Rigidbody rb;
- public float s = 10f;
- public float bs = 100f;
- public float score;
- public float rs = 100f;
- Vector3 v, r;
- public float j = 0f;
- public GameObject sp, bullet;
- AudioSource audioSource;
- // Start is called before the first frame update
- void Start()
- {
- rb = GetComponent<Rigidbody>();
- sp = GameObject.Find("BulletSpawn");
- audioSource = GetComponent<AudioSource>();
- }
- // Update is called once per frame
- void Update()
- {
- float x = 0, y = 0, z = 0;
- // float j = 0;
- if (Input.GetKey(KeyCode.W))
- {
- z = 1;
- }
- if (Input.GetKey(KeyCode.S))
- {
- z = -1;
- }
- if (Input.GetKey(KeyCode.D))
- {
- y = 1;
- }
- if (Input.GetKey(KeyCode.A))
- {
- y = -1;
- }
- if (Input.GetKeyDown(KeyCode.Space))
- {
- audioSource.Play();
- GameObject b = Instantiate(bullet, sp.transform.position, sp.transform.rotation);
- Vector3 bsp = new Vector3(0, 0, 1) * bs;
- b.GetComponent<Rigidbody>().AddRelativeForce(bsp);
- Destroy(b, 3f);
- }
- // if (Input.GetKey(KeyCode.Space))
- // {
- // if (transform.position.y <= 0.55)
- // {
- // j = 20;
- // z += 1;
- // }
- // }
- v = new Vector3(x, 0, z) * s;
- r = new Vector3(0, y, 0) * rs;
- }
- private void FixedUpdate()
- {
- rb.AddTorque(r);
- rb.AddRelativeForce(v);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement