Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Arrow : MonoBehaviour
- {
- public float speed;
- private Rigidbody2D rb;
- public GameObject arrow;
- public GameObject Player;
- // Start is called before the first frame update
- void Start()
- {
- rb = GetComponent<Rigidbody2D>();
- // for (int i = 0; i < 5; i++)
- // {
- // Instantiate(arrow);
- // }
- }
- // Update is called once per frame
- void Update()
- {
- rb.velocity = new Vector2(speed, 0);
- }
- public void OnCollisionEnter2D(Collision2D coll)
- {
- if (coll.gameObject.tag == "End")
- Destroy(gameObject);
- if (coll.gameObject.tag == "Player")
- {
- // Уменьшаем здоровье игрока и удаляем стрелу
- Player.GetComponent<Player>().health -= 1;
- Destroy(gameObject);
- }
- }
- }
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class ArrowSpawn : MonoBehaviour
- {
- [SerializeField] private GameObject obj;
- float y;
- Vector2 whereToSpawn;
- [SerializeField] private float spawnRate = 2f;
- float nextSpawn = 0.0f;
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- if (Time.time > nextSpawn)
- {
- nextSpawn = Time.time + spawnRate;
- y = -6f;
- whereToSpawn = new Vector2(transform.position.x, y);
- Instantiate(obj, whereToSpawn, Quaternion.identity);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement