Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class CanoneController : MonoBehaviour
- {
- LevelManager levelManager;
- public float cannonTimer = 2;
- public GameObject cannonEmitter;
- public GameObject cannonball;
- public float cannonballSpeed;
- bool firstBall;
- int counter = 0;
- Rigidbody[] cannonballs;
- void Start() {
- firstBall = false;
- cannonballs = new Rigidbody[100];
- levelManager = GameObject.Find("LevelManager").GetComponent<LevelManager>();
- }
- void Update()
- {
- if(levelManager.win == false) {
- cannonTimer -= Time.deltaTime;
- if (cannonTimer < 0)
- {
- GameObject temp_cannonball;
- temp_cannonball = Instantiate(cannonball, cannonEmitter.transform.position, cannonEmitter.transform.rotation) as GameObject;
- Rigidbody temp_rb;
- temp_rb = temp_cannonball.GetComponent<Rigidbody>();
- cannonballs[counter] = temp_rb;
- //temp_rb.AddForce(transform.forward * cannonballSpeed);
- Destroy(temp_cannonball, 4.0f);
- cannonTimer = 2;
- firstBall = true;
- counter++;
- }
- if (firstBall)
- {
- cannonballs[counter - 1].AddForce(transform.forward * cannonballSpeed);
- }
- }
- }
- }
- //https://www.youtube.com/watch?v=FD9HZB0Jn1w
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement