【发布时间】:2022-12-05 01:10:57
【问题描述】:
这是整个错误“int”不包含“TakeDamage”的定义,并且找不到接受类型“int”的第一个参数的可访问扩展方法“TakeDamage”(您是否缺少 using 指令或程序集引用?)
这是我应该从那里获取信息的记录
我在收到错误消息的地方写了一段文字
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerStatus : MonoBehaviour
{
//health
public int health;
public int maxHealth = 10;
//Damage
int dmg = 4;
//XP
public int xp;
public int LevelUp = 10;
// Start is called before the first frame update
void Start()
{
health = maxHealth;
}
// Update is called once per frame
public void TakeDamage(int amount)
{
health -= amount;
if(health <=0)
{
Destroy(gameObject);
}
}
}
这是应该接收信息的脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnmStatus : MonoBehaviour
{
public PlayerStatus playerHealth;
public int damage = 2;
//health
public int health;
public int maxHeath = 10;
// Start is called before the first frame update
void Start()
{
health = maxHeath;
}
// Update is called once per frame
void Update()
{
}
*//Down here I receive the error*
private void OnMouseDown()
{
health.TakeDamage(damage);
// if(health \>= 1)
// {
// playerHealth.TakeDamage(damage);
// }
}
void TakeDamage(int amount)
{
health -= amount;
if (health <= 0)
{
Destroy(gameObject);
}
}
}
当我点击他时应该会降低 ENM 的健康,之后如果 ENM 还活着我想降低玩家的健康(健康> = 1)
【问题讨论】:
标签: c# visual-studio unity3d