-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathburingFire.cs
67 lines (53 loc) · 1.62 KB
/
buringFire.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class buringFire : MonoBehaviour
{
// Start is called before the first frame update
public float duration;//持续时长
public float interval;//间隔
[HideInInspector]
public float damage;
private AudioSource audioSource;
public AudioClip cracksound;
public AbstractTurrent[] allExistingTurrent;
public List<AbstractTurrent> Targets;
//ContactFilter2D cd;
private bool collectingData = true;
float nextFire = 0;
void Start()
{
audioSource = GetComponent<AudioSource>();
audioSource.PlayOneShot(cracksound);
Destroy(gameObject, duration);
//cd = new ContactFilter2D();
}
// Update is called once per frame
void Update()
{
Targets.Clear();
allExistingTurrent = GameObject.FindObjectsOfType<AbstractTurrent>();
foreach (AbstractTurrent abst in allExistingTurrent)
{
if (Vector3.Distance(abst.gameObject.transform.position, transform.position) <= 2.9f)
{
if (abst != null)
Targets.Add(abst);
}
}
if (Time.time > nextFire)
{
nextFire = Time.time + interval;
foreach (AbstractTurrent g in Targets)
{
try
{
//Debug.Log("燃烧弹伤害:" + damage);
g.gameObject.GetComponent<AbstractTurrent>().takeDamage(damage);
}
catch (Exception e) { }
}
}
}
}