67 lines
2.1 KiB
C#
67 lines
2.1 KiB
C#
using UnityEngine;
|
|
|
|
public class ThrowFakeObject : MonoBehaviour
|
|
{
|
|
public FishingPlayer fishingPlayer;
|
|
|
|
private RaycastHit hit = default(RaycastHit);
|
|
|
|
private LayerMask mask = -1;
|
|
|
|
private void Start()
|
|
{
|
|
fishingPlayer = GameController.Instance.fishingPlayer;
|
|
mask = LayerMask.GetMask("Default", "Terrain", "Boat", "MovingPlatform");
|
|
}
|
|
|
|
private void OnCollisionEnter(Collision col)
|
|
{
|
|
if (fishingPlayer.currentHands.baitWasThrown)
|
|
{
|
|
CheckCollision(col);
|
|
}
|
|
}
|
|
|
|
private void OnCollisionStay(Collision col)
|
|
{
|
|
if (fishingPlayer.currentHands.baitWasThrown)
|
|
{
|
|
CheckCollision(col);
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (fishingPlayer.currentHands.baitWasThrown)
|
|
{
|
|
CheckRaycast();
|
|
}
|
|
}
|
|
|
|
public void CheckCollision(Collision col)
|
|
{
|
|
if (!fishingPlayer.currentHands.ThrowObjectOnWater() && fishingPlayer.currentHands.baitWasThrown && !GameController.Instance.iceLevel && (base.transform.position.y > 0f || fishingPlayer.currentHands.bait.canHitWater))
|
|
{
|
|
OnObstacle(col.gameObject);
|
|
Debug.Log("ThrowFakeObject OnObstacle CheckCollision: " + col.collider.gameObject.name + " " + ((col.contacts.Length <= 0) ? string.Empty : col.contacts[0].point.ToString()) + " " + fishingPlayer.currentHands.transform.parent.name);
|
|
}
|
|
}
|
|
|
|
public void CheckRaycast()
|
|
{
|
|
Vector3 vector = fishingPlayer.transform.position + new Vector3(0f, 2.2f, 0f);
|
|
Debug.DrawRay(vector, base.transform.position, Color.red);
|
|
if (!fishingPlayer.currentHands.ThrowObjectOnWater() && fishingPlayer.currentHands.baitWasThrown && !GameController.Instance.iceLevel && (base.transform.position.y > 0f || fishingPlayer.currentHands.bait.canHitWater) && Physics.Raycast(vector, base.transform.position - vector, out hit, Vector3.Distance(base.transform.position, vector), mask))
|
|
{
|
|
OnObstacle(hit.collider.gameObject);
|
|
Debug.Log(string.Concat("ThrowFakeObject OnObstacle CheckRaycast: ", hit.collider.gameObject.name, " ", hit.point, " ", fishingPlayer.currentHands.transform.parent.name));
|
|
}
|
|
}
|
|
|
|
public void OnObstacle(GameObject obstacleObject)
|
|
{
|
|
fishingPlayer.LineBreak(Utilities.GetTranslation("HUD_MESSAGE/BAIT_HIT_OBSTACLE"), 0f);
|
|
fishingPlayer.BlockMouseLook(false);
|
|
}
|
|
}
|