Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 团结奋斗打造无穷无尽的跑步者游戏2d_C#_Unity3d_Communityengine - Fatal编程技术网

C# 团结奋斗打造无穷无尽的跑步者游戏2d

C# 团结奋斗打造无穷无尽的跑步者游戏2d,c#,unity3d,communityengine,C#,Unity3d,Communityengine,嗨,我正在尝试在Unity Engine中构建一个无止境的跑步者gane,我一直收到这个错误消息。 找不到类型或命名空间名称“Player”(是否缺少using指令或程序集引用) 这是我的密码 using System.Collections; using System.Collections.Generic; using UnityEngine; public class obsticale : MonoBehaviour { public int damage = 1; p

嗨,我正在尝试在Unity Engine中构建一个无止境的跑步者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);
        }
    }
}
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
公共类淫秽:单一行为
{
公共int损害=1;
公众浮标速度;
私有void更新()
{
transform.Translate(Vector2.left*速度*时间.deltaTime);
}
无效OnTiggerEnter2D(碰撞的R2D其他)
{
如果(其他比较标记(“玩家”)){
//普莱尔受到伤害!
other.GetComponent().health-=损坏;
Debug.Log(other.GetComponent().health);
摧毁(游戏对象);
}
}
}
您有打字错误

应该是
other.gameObject.CompareTag(“玩家”)

下面还有很多其他的打字错误

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);
    }
void OnTriggerInter2d(碰撞的R2D其他)
{
if(other.gameObject.CompareTag(“玩家”))
{
//玩家受到伤害!
player=other.gameObject;
player.GetComponent().health-=伤害;
Log(player.GetComponent().health);
摧毁(玩家);
}

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

代码块在哪里。我不知道它在哪里。我正在使用该应用程序。