C# 团结奋斗打造无穷无尽的跑步者游戏2d
嗨,我正在尝试在Unity Engine中构建一个无止境的跑步者gane,我一直收到这个错误消息。 找不到类型或命名空间名称“Player”(是否缺少using指令或程序集引用) 这是我的密码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
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);
摧毁(玩家);
}
编辑:我也知道你是新来的,但我相信人们更希望你将代码放在网站上指定的代码块中,以便我们更容易地帮助你。代码块在哪里。我不知道它在哪里。我正在使用该应用程序。