Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.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# 确认单击某个对象后没有与该对象发生碰撞_C#_Unity3d_Collision_Game Physics - Fatal编程技术网

C# 确认单击某个对象后没有与该对象发生碰撞

C# 确认单击某个对象后没有与该对象发生碰撞,c#,unity3d,collision,game-physics,C#,Unity3d,Collision,Game Physics,如果我点击某个“航路点”,我很难找到一种方法来检查玩家是否与该“航路点”发生碰撞。我已经设置了玩家想要移动到的7个航路点 现在,我正在尝试编写一段脚本,检查单击航路点(onMouseDown)后是否与播放器发生碰撞。因为如果是这种情况,它不会计算移动到的位置 public class WayPointPositioner : MonoBehaviour { private Vector3 wayPointPosition; public GameObject playercheck; //C

如果我点击某个“航路点”,我很难找到一种方法来检查玩家是否与该“航路点”发生碰撞。我已经设置了玩家想要移动到的7个航路点

现在,我正在尝试编写一段脚本,检查单击航路点(onMouseDown)后是否与播放器发生碰撞。因为如果是这种情况,它不会计算移动到的位置

public class WayPointPositioner : MonoBehaviour {

private Vector3 wayPointPosition;
public GameObject playercheck;

//Check if object is clicked
void OnMouseDown () 
{
    Debug.Log ("Object Clicked " + GameObject.name);

    // Check if collision occurs with playercheck

    OnCollisionEnter(playercheck != Collision)
    {
        // If its the player, then return a new position for the player to move to for walking
        // Else debug that its not so
        if (playercheck.gameObject.CompareTag("Player"))
        {

            Debug.Log ("Object not colliding and retrieving position");

            wayPointPosition = new Vector3 (GameObject.X, GameObject.Y, 10);
            wayPointPosition = Camera.main.ScreenToWorldPoint(wayPointPosition);

        }
        else
        {

            Debug.Log ("Object is colliding, no movement needed");

        }
    }
}

}

现在我已经发现,
OnCollisionCenter
无法工作。因为它需要在它之前使用void语句才能正常工作。但是我不知道我还能做什么。

我只是比较一下球员的位置和路点。如果相等,则玩家在那里,否则移动到路径点。希望我正确理解这个问题。

设法解决了它。我只是个白痴

关键是分别使用这两种功能。因此,我将检查Mousedown和检查位置是否被占用的任务分为两部分:创建一个单独的变量,从中询问true或false,以检查所有内容

public class WayPointPositioner : MonoBehaviour {

private Vector3 wayPointPosition;
private bool checkPlayerWaypointCollision;

void Start()
{
    wayPointPosition = transform.position;
}

void OnTriggerStay2D (Collider2D other) 
{
    if (other.gameObject.name == "Player")
    {
        checkPlayerWaypointCollision = true;
    }
    else
    {
        checkPlayerWaypointCollision = false;
    }

}

//Check if object is clicked
void OnMouseDown () 
{

    // If its the player, then return a new position for the player to move to for walking
    // Else debug that its not so
        if (checkPlayerWaypointCollision == false)
        {

            Debug.Log ("Object not colliding and retrieving position");

            transform.position = new Vector3 (transform.position.x, transform.position.y, 10);
            wayPointPosition = Camera.main.ScreenToWorldPoint(wayPointPosition);

        }
        else
        {

            Debug.Log ("Object is colliding, no movement needed");

        }

}

}

不,航路点系统在那里,因此最终玩家角色将沿着航路点移动到航路点目的地。示例:他从02航路点出发,需要前往06航路点。然后通过03-04-05到达06。