Initial commit
This commit is contained in:
59
code-csharp/en_US/PushBlock_CollisionPrediction.cs
Normal file
59
code-csharp/en_US/PushBlock_CollisionPrediction.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class PushBlock_CollisionPrediction : MonoBehaviour
|
||||
{
|
||||
public bool Colliding;
|
||||
|
||||
public bool printresult;
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (!Colliding && other.tag != "Player" && other.tag != "PuzzlePushBlock")
|
||||
{
|
||||
Colliding = true;
|
||||
if (printresult)
|
||||
{
|
||||
MonoBehaviour.print(other.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerStay2D(Collider2D other)
|
||||
{
|
||||
if (!Colliding && other.tag != "Player" && other.tag != "PuzzlePushBlock")
|
||||
{
|
||||
Colliding = true;
|
||||
}
|
||||
if (printresult)
|
||||
{
|
||||
MonoBehaviour.print(other.name);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerExit2D(Collider2D other)
|
||||
{
|
||||
if (Colliding && other.tag != "Player" && other.tag != "PuzzlePushBlock")
|
||||
{
|
||||
Colliding = false;
|
||||
}
|
||||
if (printresult)
|
||||
{
|
||||
MonoBehaviour.print(other.name);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
Vector2 vector = new Vector2(PlayerManager.Instance.transform.position.x, PlayerManager.Instance.transform.position.y);
|
||||
Vector2 vector2 = new Vector2(base.transform.parent.position.x, base.transform.parent.position.y);
|
||||
Vector2 vector3 = vector2 - vector;
|
||||
if (Mathf.Abs(vector3.x) > Mathf.Abs(vector3.y))
|
||||
{
|
||||
base.transform.position = vector2 + new Vector2(Mathf.Sign(vector3.x), 0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.transform.position = vector2 + new Vector2(0f, Mathf.Sign(vector3.y));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user