Advertisement
lemansky

Untitled

Apr 14th, 2024 (edited)
1,181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class MagicArrow : MonoBehaviour
  6. {
  7.     // Start is called before the first frame update
  8.     public GameObject prefab;
  9.     public GameObject prefabCast;
  10.     public float shootCooldown = 0.2f;
  11.     public float shootTimer = -1.0f;
  12.     private GameObject target;
  13.     private ParticleSystem Effect;
  14.  
  15.     void Update()
  16.     {
  17.         if (Input.GetKeyDown(KeyCode.Alpha1))
  18.         {
  19.             ShootMagic();
  20.         }
  21.     }
  22.    
  23.     void ShootMagic()
  24.     {
  25.         for(int i = 0; i < 5; i++)
  26.         {
  27.             GameObject projectile = Instantiate(prefabCast, transform.position, transform.rotation);
  28.             target = GameObject.FindGameObjectWithTag("Enemy") ?? null;
  29.             if (target != null)
  30.             {
  31.                 projectile.GetComponent<TargetProjectile>().UpdateTarget(target.transform, Vector3.zero);
  32.                 Effect = prefab.GetComponent<ParticleSystem>();
  33.                 Effect.Play();
  34.             }
  35.         }
  36.        
  37.     }
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement