Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Mirror;
  5.  
  6. public class Projectile : NetworkBehaviour
  7. {
  8.  
  9.     public float speed;
  10.     public float lifeTime;
  11.     public float distance;
  12.     public int damage;
  13.     public LayerMask whatIsSolid;
  14.  
  15.     //public GameObject destroyEffect;
  16.  
  17.     private void Start()
  18.     {
  19.         Invoke("DestroyProjectile", lifeTime);
  20.     }
  21.  
  22.     private void Update()
  23.     {
  24.         RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, transform.right, distance, whatIsSolid);
  25.         if (hitInfo.collider != null)
  26.         {
  27.             if (hitInfo.collider.CompareTag("Player"))
  28.             {
  29.                 hitInfo.collider.GetComponentInParent<PlayerMovement>().TakeDamage(damage);
  30.             }
  31.             DestroyProjectile();
  32.         }
  33.  
  34.  
  35.         transform.Translate(Vector2.right * speed * Time.deltaTime);
  36.     }
  37.  
  38.    
  39.     void DestroyProjectile()
  40.     {
  41.         //Instantiate(destroyEffect, transform.position, Quaternion.identity);
  42.         Destroy(gameObject);
  43.     }
  44.  
  45.    
  46.  
  47.    
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement