Guest User

Unity 3D - Instantiate when last object hit

a guest
Apr 25th, 2020
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. public class weaponScript : MonoBehaviour
  2. {
  3.         public gameobject projectilePrefab;
  4.         public bool launchable;
  5.         private projectile projectileScript;
  6.  
  7.         void Update{
  8.         if(launchable){
  9.             GameObject projectileIntantiated = Instantiate(projectilePrefab, firePoint.transform.position, transform.rotation);
  10.             projectileScript = projectileIntantiated.GetComponent<projectile>();
  11.             projectileScript.parentWeapon = this.gameObject.GetComponent<weaponScript>();
  12.             launchable = false;
  13.         }
  14.     }
  15.  
  16.  
  17. public class projectile : MonoBehaviour
  18. {
  19.     public weaponScript parentWeapon;
  20.  
  21.     void OnCollisionEnter2D(Collision2D other){
  22.         parentWeapon.launchable = true;
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment