Repository navigation
Expand file tree
/
Copy pathGreenUFO.cs
More file actions
56 lines (49 loc) · 1.37 KB
/
Copy pathGreenUFO.cs
File metadata and controls
56 lines (49 loc) · 1.37 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
46
47
48
49
50
51
52
53
54
55
56
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class GreenUFO : Entity
{
/** <summary> 移動方向のベクトル </summary> */
private Vector2 moveVec;
// Start is called before the first frame update
protected override void Start()
{
base.Start();
}
// Update is called once per frame
protected override void Update()
{
base.Update();
Move();
}
private void Move()
{
Rigidbody2D rigidbody = GetComponent<Rigidbody2D>();
// 進めないとき
if (TouchingRigidbodies(moveVec).Count > 0)
{
GameObject playerObject = GameObject.Find("Player");
if(playerObject != null)
{
moveVec =
(playerObject.transform.position -
transform.position).normalized;
}
else
{
float theta = Random.Range(0, 2 * Mathf.PI);
Vector2 v = new Vector2(Mathf.Cos(theta), Mathf.Sin(theta));
moveVec = (v + 0.5f * moveVec).normalized;
}
}
rigidbody.velocity = 2f * moveVec;
}
private void OnCollisionStay2D(Collision2D collision)
{
if (collision.collider.TryGetComponent(out Player player))
{
player.Damaged();
}
}
}