m0_64580933 2022-04-06 13:57 采纳率: 100%
浏览 15
已结题

攻击指令调用问题,求帮助

#Attack();无法调用
#using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyAttact : MonoBehaviour {
public int attackDamage = 10;
public float timeBetweenAttck = 0.5f;
private GameObject player;
private PlayerHealth playerHealth;
private bool playerInRanger;
private float time;
private void Awake()
{
player = GameObject.FindGameObjectWithTag("Player");
playerHealth=player.GetComponent();
}
private void onTriggerEnter(Collider other)
{
if (other.gameObject == player)
playerInRanger = true;
}
private void OnTriggerExit(Collider other)
{
if(other.gameObject == player)
playerInRanger= false;
}
void Update () {
if (playerInRanger&&time>=timeBetweenAttck&&playerHealth.currentHealth>=0)
{
time = time + Time.deltaTime;
Attack();
}
}
private void Attack()
{
time = 0;
playerHealth.TakeDamage(attackDamage);
}
}

  • 写回答

1条回答 默认 最新

  • m0_64580933 2022-04-07 16:34
    关注

    time放在前面

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 4月15日
  • 已采纳回答 4月7日
  • 修改了问题 4月6日
  • 创建了问题 4月6日