Advertisement
Guest User

Untitled

a guest
Jul 11th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. public void Fire() {
  2. if (asset.projectile == null) {
  3. Debug.Log("No projectile set up for gun part " + asset.dbName + "!");
  4. return;
  5. }
  6. for (int i = 0; i < asset.projectileQuantity; ++i) {
  7. var p = GameObject.Instantiate(asset.projectile);
  8. p.layer = gameObject.layer;
  9. // Align projectile with the barrel.
  10. // TODO: add scatter
  11. p.transform.position = turret.transform.position;
  12. p.transform.eulerAngles = barrel.transform.eulerAngles;
  13.  
  14. var rbod = p.GetComponent<Rigidbody>();
  15. rbod.useGravity = asset.useGravity;
  16. rbod.AddRelativeForce(0, launchVelocity, 0, ForceMode.VelocityChange);
  17.  
  18. var comp = p.AddComponent<Projectile>();
  19. comp.damage = asset.damage;
  20. comp.debug = (i == 0 && Time.renderedFrameCount == 10);
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement