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.

49 lines
1.2 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using TMPro;
  4. using UnityEngine;
  5. public class ShootingCannon : MonoBehaviour
  6. {
  7. public bool shootingRight;
  8. public bool triggeranimate;
  9. public GameObject shootingObject;
  10. public Transform spawnLocation;
  11. public TextMeshPro counter;
  12. public int countdowntimer;
  13. int countdown;
  14. private void Start()
  15. {
  16. countdown = countdowntimer;
  17. }
  18. private void Update()
  19. {
  20. counter.text = countdown.ToString();
  21. //for testing purposes
  22. if (triggeranimate == true)
  23. {
  24. Animate();
  25. triggeranimate = false;
  26. }
  27. }
  28. public void Animate()
  29. {
  30. countdown--;
  31. // if (countdown == 0){
  32. GameObject shot = Instantiate(shootingObject, spawnLocation.position, Quaternion.identity);
  33. if (shootingRight == true)
  34. {
  35. shot.GetComponent<Rigidbody>().AddForce(shot.transform.forward * -500);
  36. }
  37. else
  38. {
  39. shot.GetComponent<Rigidbody>().AddForce(shot.transform.forward * 500);
  40. }
  41. countdown = countdowntimer;
  42. //}
  43. }
  44. }