Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class CanoneController : MonoBehaviour
  6. {
  7.  
  8. LevelManager levelManager;
  9.  
  10. public float cannonTimer = 2;
  11. public GameObject cannonEmitter;
  12. public GameObject cannonball;
  13. public float cannonballSpeed;
  14. bool firstBall;
  15. int counter = 0;
  16. Rigidbody[] cannonballs;
  17.  
  18. void Start() {
  19. firstBall = false;
  20. cannonballs = new Rigidbody[100];
  21. levelManager = GameObject.Find("LevelManager").GetComponent<LevelManager>();
  22. }
  23.  
  24. void Update()
  25. {
  26. if(levelManager.win == false) {
  27. cannonTimer -= Time.deltaTime;
  28. if (cannonTimer < 0)
  29. {
  30. GameObject temp_cannonball;
  31. temp_cannonball = Instantiate(cannonball, cannonEmitter.transform.position, cannonEmitter.transform.rotation) as GameObject;
  32. Rigidbody temp_rb;
  33. temp_rb = temp_cannonball.GetComponent<Rigidbody>();
  34. cannonballs[counter] = temp_rb;
  35. //temp_rb.AddForce(transform.forward * cannonballSpeed);
  36. Destroy(temp_cannonball, 4.0f);
  37. cannonTimer = 2;
  38. firstBall = true;
  39. counter++;
  40. }
  41.  
  42. if (firstBall)
  43. {
  44. cannonballs[counter - 1].AddForce(transform.forward * cannonballSpeed);
  45. }
  46. }
  47.  
  48.  
  49. }
  50.  
  51. }
  52.  
  53. //https://www.youtube.com/watch?v=FD9HZB0Jn1w
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement