团结斗争使无尽的亚军游戏2d



嗨,我正在尝试在 Unity 引擎中构建一个无休止的运行者 gane,但我不断收到此错误消息。 找不到类型或命名空间名称"Player"(是否缺少 using 指令或程序集引用(

这是我的代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class obsticale : MonoBehaviour
{
public int damage = 1;
public float speed;
private void Update()
{
transform.Translate(Vector2.left * speed * Time.deltaTime);
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player")) {
//plaer takes damage!
other.GetComponent<Player>().health -= damage;
Debug.Log(other.GetComponent<Player>().health);
Destroy(gameObject);
}
}
}

你有错别字。

应该other.gameObject.CompareTag("Player")

下面还有多个其他错别字。

void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("Player"))) 
{
//player takes damage!
player = other.gameObject;
player.GetComponent<yourscriptname>().health -= damage;
Debug.Log(player.GetComponent<yourscriptname>().health);
Destroy(player);
}

编辑:我也知道你是新来的,但我相信人们宁愿你把你的代码放在网站上的指定代码块里,以便我们更容易帮助你。

最新更新