blob: 697cbdc6b3b6432ab095331879e84e18e0dc4b24 (
plain)
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
|
using UnityEngine;
using System.Collections;
public class Enemy3FireScript : MonoBehaviour {
float FireRate = 1f;
float fireCounter;
public bool PlayerInRange;
public GameObject Bullet;
public float BulletSpeed = 20;
Enemy3AttackScript enemy3AttackScript;
AudioSource EnemyFireAudio;
void Start()
{
enemy3AttackScript = GetComponent<Enemy3AttackScript>();
EnemyFireAudio = GameObject.FindGameObjectWithTag("EnemyFireAudio").GetComponent<AudioSource>();
}
void Update()
{
fireCounter += Time.deltaTime;
if (fireCounter >= FireRate && PlayerInRange)
{
fireCounter = 0;
EnemyFireAudio.Play();
if (enemy3AttackScript.isRight)
Fire(1);
else
Fire(-1);
}
}
void Fire(float x)
{
var Bullet1 = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity) as GameObject;
Bullet1.GetComponent<Rigidbody2D>().velocity = Vector2.right * BulletSpeed * x;
Destroy(Bullet1, 2f);
}
}
|