-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTurretShoot.cs
53 lines (43 loc) · 1.54 KB
/
TurretShoot.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TurretShoot : MonoBehaviour {
[SerializeField]private Transform Player;
public float bulletSpeed;
public float bulletTime;
public float interval;
public GameObject bullet;
public float distance;
[SerializeField]private Transform magicTurret1B;
[SerializeField]private Transform magicTurretB;
[SerializeField]private Transform magicTurret1;
[SerializeField]private Transform magicTurret;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
distance = Vector3.Distance (transform.position, Player.transform.position);
}
public void Attack (){
bulletTime += Time.deltaTime;
if (bulletTime >= interval && (magicTurret)) {
GameObject lightningbullet;
lightningbullet = Instantiate (bullet, magicTurretB.transform.position, magicTurretB.transform.rotation)as GameObject;
lightningbullet.GetComponent<Rigidbody2D> ().velocity = Vector2.left * bulletSpeed;
bulletTime = 0;
}
if (bulletTime >= interval && (magicTurret1)) {
GameObject lightningbullet1;
lightningbullet1 = Instantiate (bullet, magicTurret1B.transform.position, magicTurret1B.transform.rotation)as GameObject;
lightningbullet1.GetComponent<Rigidbody2D> ().velocity = Vector2.left * bulletSpeed;
bulletTime = 0;
}
}
void OnTriggerEnter2D(Collider2D other){
if (other.tag == "goodBullet") {
Destroy (other);
Destroy (gameObject);
}
}
}