本文整理汇总了C#中UnityEngine.Collider2D.OverlapPoint方法的典型用法代码示例。如果您正苦于以下问题:C# Collider2D.OverlapPoint方法的具体用法?C# Collider2D.OverlapPoint怎么用?C# Collider2D.OverlapPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Collider2D
的用法示例。
在下文中一共展示了Collider2D.OverlapPoint方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnTriggerStay2D
void OnTriggerStay2D(Collider2D col)
{
///get position of click
clickPosition.x = Camera.main.ScreenToWorldPoint(Input.mousePosition).x;
clickPosition.y = Camera.main.ScreenToWorldPoint(Input.mousePosition).y;
///currently, click must be on player
if (col.tag == "Player" && ((Input.GetKeyDown(KeyCode.Space)) || (col.OverlapPoint(clickPosition) && Input.GetMouseButtonDown(0))))
{
if (exit != null)
{
cameraScript.follow = false;
cameraScript.target = exit.transform;
}
else
{
Debug.Log("no exit assigned");
}
Debug.Log("Teleport Complete!"); // confirm that teleport is complete; this can be taken out
TeleportToExit2D(col);
}
/*
else
{
//cameraScript.follow = true;//allows smooth transition for each teleport
}
*/
}
示例2: OnTriggerStay2D
void OnTriggerStay2D( Collider2D col)
{
///get position of click
clickPosition.x = Camera.main.ScreenToWorldPoint(Input.mousePosition).x;
clickPosition.y = Camera.main.ScreenToWorldPoint(Input.mousePosition).y;
///currently, click must be on player
if (col.tag == "Player" && ((Input.GetKeyDown(KeyCode.Space))||(col.OverlapPoint(clickPosition) && Input.GetMouseButtonDown(0))))
{
Debug.Log("Teleport Complete!"); // confirm that teleport is complete; this can be taken out
TeleportToExit2D(col);
}
}
示例3: OnTriggerStay2D
//allows actions when staying within collision area
void OnTriggerStay2D(Collider2D col)
{
// OverlapPoint refers to world space instead of screen space, adjusting accordingly
clickPosition.x = (Camera.main.ScreenToWorldPoint(Input.mousePosition).x);
clickPosition.y = (Camera.main.ScreenToWorldPoint(Input.mousePosition).y);
//Toggle Hide/Unhide
if ((Input.GetKeyDown(KeyCode.Space) || (Input.GetMouseButtonDown(0) && col.OverlapPoint(clickPosition)))) //if player activates hiding spot
//|| ((hide && ((Input.GetAxis("Horizontal") > 0.9)||(Input.GetAxis("Horizontal") < -0.9))) //or if player is hidden and moves using the keyboard
//|| (hide && Input.GetMouseButton(0)&& (Input.mousePosition.x < edgeLeft.x || Input.mousePosition.x > edgeRight.x)))) //or if player is hidden and moves using the mouse
{
if (col.gameObject.tag == "Cover")
{
if (!hide)
{
sprite.sortingOrder = hidingOrder;
hide = true;
}
else if (hide)
{
sprite.sortingOrder = sortingOrder;
hide = false;
if (slowMo) //Disables slowmotion speed upon hiding
{
slowMo = false;
}
}
}
//if player is trying to hide, and the object is the trap enemy
else if (col.gameObject.tag == "Enemy")
{
//player dies
isAlive = false;
//prevents movement
normalSpeed = 0f;
}
}
//if player colliders with an enemy and is not hidden
if (col.gameObject.tag == "PatrolEnemy" && hide == false)
{
//player is dead
isAlive = false;
//prevent player from moving
normalSpeed = 0f;
}
///gameover for stationary enemies handled in their own code
}
示例4: OnTriggerStay2D
//allows actions when staying within collision area
void OnTriggerStay2D(Collider2D col)
{
// OverlapPoint refers to world space instead of screen space, adjusting accordingly
clickPosition.x = (Camera.main.ScreenToWorldPoint(Input.mousePosition).x);
clickPosition.y = (Camera.main.ScreenToWorldPoint(Input.mousePosition).y);
//Toggle Hide/Unhide
if ((Input.GetKeyDown(KeyCode.Space) || (Input.GetMouseButtonDown(0)&& col.OverlapPoint(clickPosition))))
{
if (col.gameObject.tag == "Cover")
{
if (!hide)
{
sprite.sortingOrder = hidingOrder;
hide = true;
}
else if (hide)
{
sprite.sortingOrder = sortingOrder;
hide = false;
if (slowMo) //Disables slowmotion speed upon hiding
{
slowMo = false;
}
}
}
}
//if player colliders with an enemy and is not hidden
if (col.gameObject.tag == "PatrolEnemy" && hide == false)
{
//player is dead
isAlive = false;
//prevent player from moving
normalSpeed = 0f;
}
///gameover for stationary enemies handled in their own code
}
示例5: IsHeroNearWayout
private bool IsHeroNearWayout(Collider2D wayout, bool central)
{
if (_hero == null)
return false;
Vector2 position = _hero.transform.position;
if (central)
position.y -= 0.7f;
Vector3 position2check = new Vector3(position.x, position.y, wayout.transform.position.z);
return wayout.OverlapPoint(position2check);
}