找不到类型或名称空间名称“ Player”

时间:2018-10-05 02:50:54

标签: c# unity3d using

PL,我正在Unity和Visual Studio中从事一个项目,它总是给我带来错误,外观。

using UnityEngine;
using UnityEditor.Build.Player;

public class Obsticle : 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")) {

            other.GetComponent<Player>().health -= damage;
            Debug.Log(other.GetComponent<Player>().health);
            Destroy(gameObject);
        }
    }
}

1 个答案:

答案 0 :(得分:0)

首先,建立自己的玩家类会导致冲突。换课 名称,也不要使用字符。大声笑。我用盖伊。播放器标记很好,并且已固定。还:

void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.Tag=="Player") {

            other.GetComponent<Guy>().health -= damage;
            Debug.Log(other.GetComponent<Guy>().health);
            Destroy(gameObject);
        }
    }

这是我的接听类OnTrigger方法之一,

private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "Player")
        {

            //destroy 'obsticle'
            Destroy(this.gameObject);
        }
    }
相关问题