基本就是改了改出处。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerAttack1 : MonoBehaviour
{
public int damage;
public float startTime;
public float time;
private Animator anim;
private CircleCollider2D collider2D;
// Start is called before the first frame update
void Start()
{
anim = GameObject.FindGameObjectWithTag("Player").GetComponent<Animator>();
collider2D = GetComponent<CircleCollider2D>();
}
// Update is called once per frame
void Update()
{
PlayerAttackJinZhan();
}
void PlayerAttackJinZhan()
{
if (Input.GetButtonDown("Attack"))
{
StartCoroutine(StartAttack());
}
}
IEnumerator StartAttack()
{
yield return new WaitForSeconds(startTime);
collider2D.enabled = true;
StartCoroutine(disableHitBox());
}
IEnumerator disableHitBox()
{
yield return new WaitForSeconds(time);
collider2D.enabled = false;
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("Enemy"))
{
other.GetComponent<Enemy>().TakeDamage(damage);
}
}
}