You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
848 B

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class ShootingCannon : MonoBehaviour
  5. {
  6. public bool shootingRight;
  7. public bool triggeranimate;
  8. public GameObject shootingObject;
  9. public Transform spawnLocation;
  10. private void Update()
  11. {
  12. //for testing purposes
  13. if (triggeranimate == true)
  14. {
  15. Animate();
  16. triggeranimate = false;
  17. }
  18. }
  19. public void Animate()
  20. {
  21. GameObject shot = Instantiate(shootingObject, spawnLocation.position, Quaternion.identity);
  22. if (shootingRight == true)
  23. {
  24. shot.GetComponent<Rigidbody>().AddForce(shot.transform.forward * -500);
  25. }
  26. else
  27. {
  28. shot.GetComponent<Rigidbody>().AddForce(shot.transform.forward * 500);
  29. }
  30. }
  31. }