相关疑难解决方法(0)

Physics2D.Raycast 返回 null

我有一个问题让我在这里非常难倒。我将从关键代码到鼠标输入 - 然后它后来成为触摸输入,但首先我想弄清楚为什么我不能只用鼠标来做到这一点。

我有一个 raycast2d 设置 - 我希望 raycast 读取与屏幕上我的对象的碰撞。只有当它是一个标记为“猫”的物体时,它们才会做出反应——基本上一旦发生这种情况,猫就会冲出去并试图攻击。但是,它告诉我标签本身是一个实例化的引用。但是对象本身默认存在,所以我不确定在这里做什么。这是我的整个脚本。

 void Update() {
    //if ((Input.GetKeyDown(KeyCode.O) && !attacking && attackTimer <= 0)) {
    if (Input.GetMouseButtonDown(0) && !attacking && attackTimer <= 0) {  //every frame check to see if the mouse has been clicked.
                                                                          //Get the mouse position on the screen and send a raycast into the game world from that position.
        Vector2 worldPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);//Vector 2 means only 2 points of axis are read. worldpoint means check the point of the …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine

2
推荐指数
1
解决办法
3039
查看次数

标签 统计

c# ×1

unity-game-engine ×1