-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSword.cs
35 lines (28 loc) · 1.05 KB
/
Sword.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Sword : MonoBehaviour
{
[SerializeField] private float attackDemage;//伤害
public void EndAttack()
{
gameObject.SetActive(false);
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag == "Monster")
{
/*if (!collision.gameObject.GetComponent<Enemy>().isAttacked)
{
//Debug.Log("attack");
collision.gameObject.GetComponent<Enemy>().getAttacked(attackDemage);
//Quaternion.identity不旋转
//击退效果 向着反方向运动 怪物位置 - 角色位置
Vector2 p = collision.transform.position - transform.position;
//向量标准化
p = p.normalized;
collision.transform.position = new Vector2(collision.transform.position.x + p.x, collision.transform.position.y + p.y);
}*/
}
}
}