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.

42 lines
1.0 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. }
  22. public void Animate()
  23. {
  24. countdown--;
  25. if (countdown == 0){
  26. GameObject shot = Instantiate(shootingObject, spawnLocation.position, Quaternion.identity);
  27. if (shootingRight == true)
  28. {
  29. shot.GetComponent<Rigidbody>().AddForce(shot.transform.forward * -500);
  30. }
  31. else
  32. {
  33. shot.GetComponent<Rigidbody>().AddForce(shot.transform.forward * 500);
  34. }
  35. countdown = countdowntimer;
  36. }
  37. }
  38. }