-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBullet.cs
More file actions
45 lines (35 loc) · 1.01 KB
/
Bullet.cs
File metadata and controls
45 lines (35 loc) · 1.01 KB
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
using UnityEngine;
using System.Collections;
public class Bullet : MonoBehaviour
{
private GameObject parent;
public GameObject Parent { set { parent = value; } get { return parent; } }
private float speed = 10.0F;
private Vector3 direction;
public Vector3 Direction { set { direction = value; } }
public Color Color
{
set { sprite.color = value; }
}
private SpriteRenderer sprite;
private void Awake()
{
sprite = GetComponentInChildren<SpriteRenderer>();
}
private void Start()
{
Destroy(gameObject, 1F);
}
private void Update()
{
transform.position = Vector3.MoveTowards(transform.position, transform.position + direction, speed * Time.deltaTime);
}
private void OnTriggerEnter2D(Collider2D collider)
{
Unit unit = collider.GetComponent<Unit>();
if (unit && unit.gameObject != parent)
{
Destroy(gameObject);
}
}
}