Modification start date
[BattleCats.git] / Assets / Scripts / BossScripts / CanRotatorFire.cs
blob54a8a5270290de1354df8cd665ae16d83d308fdd
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
5 public class CanRotatorFire : MonoBehaviour {
7 public GameObject bullet;
8 public GameObject grenade;
10 public Transform shotSpawn;
12 public float rotationSpeed;
13 private float nextFire;
14 public float nextFireDelay;
15 private float nextGrenade;
16 public float nextGrenadeDelay;
17 public float grenadeLaunchPower;
19 public bool noAimSequence;
20 public bool grenadeSequence;
21 private bool rotateUp;
22 public bool isRightCan;
25 // Use this for initialization
26 void Start () {
27 noAimSequence = false;
28 grenadeSequence = false;
29 rotateUp = true;
30 isRightCan = false;
31 rotationSpeed = 40f;
32 nextFire = 0f;
33 nextFireDelay = 1.5f;
34 nextGrenade = 0f;
35 nextGrenadeDelay = 5f;
36 grenadeLaunchPower = 4f;
39 // Update is called once per frame
40 void Update () {
42 if (noAimSequence == true) {
43 NoAimSequence ();
46 if (grenadeSequence == true) {
47 GrenadeSequence ();
52 void Fire() {
54 Instantiate (bullet, shotSpawn.position, shotSpawn.rotation);
57 void DropGrenade(){
58 GameObject clone;
59 clone = Instantiate (grenade, shotSpawn.position, shotSpawn.rotation);
60 if (isRightCan) {
61 clone.GetComponent<Rigidbody2D>().velocity = transform.TransformDirection (new Vector2(1,1) * grenadeLaunchPower);
62 } else {
63 clone.GetComponent<Rigidbody2D>().velocity = transform.TransformDirection (new Vector2(-1,1) * grenadeLaunchPower);
65 clone.GetComponent<Rigidbody2D>().velocity = transform.TransformDirection (new Vector2(-1,1) * grenadeLaunchPower);
68 void NoAimSequence(){
69 if (Time.time > nextFire) {
70 Fire ();
71 nextFire = Time.time + nextFireDelay;
73 if (transform.rotation.z <= -0.3230917f) {
74 rotateUp = false;
76 if (transform.rotation.z >= 0.2873605f) {
77 rotateUp = true;
79 if (rotateUp) {
80 transform.Rotate (0, 0, -Time.deltaTime * rotationSpeed);
81 } else {
82 transform.Rotate (0, 0, Time.deltaTime * rotationSpeed);
86 void GrenadeSequence(){
87 if (Time.time > nextGrenade) {
88 DropGrenade ();
89 nextGrenade = Time.time + nextGrenadeDelay;