Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Mirror;
- public class Projectile : NetworkBehaviour
- {
- public float speed;
- public float lifeTime;
- public float distance;
- public int damage;
- public LayerMask whatIsSolid;
- //public GameObject destroyEffect;
- private void Start()
- {
- Invoke("DestroyProjectile", lifeTime);
- }
- private void Update()
- {
- RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, transform.right, distance, whatIsSolid);
- if (hitInfo.collider != null)
- {
- if (hitInfo.collider.CompareTag("Player"))
- {
- hitInfo.collider.GetComponentInParent<PlayerMovement>().TakeDamage(damage);
- }
- DestroyProjectile();
- }
- transform.Translate(Vector2.right * speed * Time.deltaTime);
- }
- void DestroyProjectile()
- {
- //Instantiate(destroyEffect, transform.position, Quaternion.identity);
- Destroy(gameObject);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement