2026-02-03 11:35:19 +08:00
|
|
|
using Assets.MyGame.Scripts.Net;
|
|
|
|
|
using Assets.MyGame.Scripts.Net.API;
|
|
|
|
|
using Assets.MyGame.Scripts.Net.WebResponses;
|
|
|
|
|
using System.Collections;
|
2025-12-26 11:15:56 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2026-02-03 11:35:19 +08:00
|
|
|
|
|
|
|
|
|
2025-12-26 11:15:56 +08:00
|
|
|
public class BullitMove : MonoBehaviour
|
|
|
|
|
{
|
2026-03-09 09:25:01 +08:00
|
|
|
public UserToken user;
|
2025-12-26 11:15:56 +08:00
|
|
|
public float moveSpeed = 5;
|
|
|
|
|
public float desTime = 10f;
|
|
|
|
|
public string playerID;
|
2025-12-26 14:43:20 +08:00
|
|
|
public GameObject effectPrefab;
|
2026-02-03 11:35:19 +08:00
|
|
|
public GameObject diePrefab;
|
2025-12-26 11:15:56 +08:00
|
|
|
float currShowTime = 0f;
|
|
|
|
|
Vector3 vector3_startPosition;
|
2026-02-03 11:35:19 +08:00
|
|
|
public bool isTriggerFirst = true;
|
|
|
|
|
MonsterContral target;
|
2026-03-09 09:25:01 +08:00
|
|
|
public string bulletID;
|
2025-12-26 11:15:56 +08:00
|
|
|
// Start is called before the first frame update
|
|
|
|
|
void Awake()
|
|
|
|
|
{
|
|
|
|
|
Init();
|
2026-02-03 11:35:19 +08:00
|
|
|
//Destroy(gameObject, desTime);
|
|
|
|
|
}
|
|
|
|
|
bool isLock = false;
|
|
|
|
|
public void Lock(MonsterContral monsterContral)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in GetComponents<Collider2D>())
|
|
|
|
|
{
|
|
|
|
|
item.enabled = false;
|
|
|
|
|
}
|
|
|
|
|
isLock = true;
|
|
|
|
|
target = monsterContral;
|
|
|
|
|
}
|
|
|
|
|
public void NotLock()
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in GetComponents<Collider2D>())
|
|
|
|
|
{
|
|
|
|
|
item.enabled = true;
|
|
|
|
|
}
|
|
|
|
|
isLock = false;
|
|
|
|
|
target = null;
|
2025-12-26 11:15:56 +08:00
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 对象池用
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Init()
|
|
|
|
|
{
|
|
|
|
|
vector3_startPosition = transform.position;
|
|
|
|
|
}
|
2026-02-03 11:35:19 +08:00
|
|
|
//子弹同步分为两种一种是锁定目标一种是不锁定目标
|
2025-12-26 11:15:56 +08:00
|
|
|
// Update is called once per frame
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
2026-02-03 11:35:19 +08:00
|
|
|
if (isLock)
|
|
|
|
|
{
|
|
|
|
|
if (target == null)
|
|
|
|
|
{
|
|
|
|
|
NotLock();
|
|
|
|
|
}
|
|
|
|
|
var ABdistance = Vector3.Distance(transform.position, target.transform.position);
|
|
|
|
|
var rotateSpeed = 1/ABdistance;
|
|
|
|
|
Vector3 targetPoint = (target.transform.position-transform.position).normalized * moveSpeed*Time.deltaTime;
|
2026-02-09 10:44:38 +08:00
|
|
|
transform.up = Vector3.Lerp(transform.up, targetPoint, rotateSpeed);
|
2026-02-03 11:35:19 +08:00
|
|
|
targetPoint = transform.up.normalized * moveSpeed * Time.deltaTime;
|
|
|
|
|
transform.position+= targetPoint;
|
|
|
|
|
if (ABdistance <= 2)
|
|
|
|
|
{
|
|
|
|
|
AttackFish(target);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//方便帧同步
|
|
|
|
|
currShowTime += Time.deltaTime;
|
|
|
|
|
Vector3 targetPoint = transform.up.normalized * currShowTime * moveSpeed;
|
|
|
|
|
transform.position = vector3_startPosition + targetPoint;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-26 11:15:56 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2026-02-03 11:35:19 +08:00
|
|
|
private void OnCollisionEnter2D(Collision2D collision)
|
2025-12-26 11:15:56 +08:00
|
|
|
{
|
|
|
|
|
if (isTriggerFirst)
|
|
|
|
|
{
|
2026-02-03 11:35:19 +08:00
|
|
|
if (collision.transform.tag == "Fish")
|
2025-12-26 11:15:56 +08:00
|
|
|
{
|
2026-02-03 11:35:19 +08:00
|
|
|
isTriggerFirst = false;
|
2025-12-26 18:19:12 +08:00
|
|
|
//击中特效
|
2026-02-03 11:35:19 +08:00
|
|
|
if (effectPrefab != null)
|
|
|
|
|
{
|
|
|
|
|
Instantiate(effectPrefab, transform.position, Quaternion.identity, transform.parent);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-26 11:15:56 +08:00
|
|
|
//受激
|
2026-02-03 11:35:19 +08:00
|
|
|
var monster = collision.transform.GetComponentInParent<MonsterContral>();
|
|
|
|
|
monster.monsterData.charactersHealth.OnHurt(10, CharacterHurtType.none);
|
|
|
|
|
Destroy(monster.gameObject);
|
2025-12-26 11:15:56 +08:00
|
|
|
Destroy(gameObject);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-03 11:35:19 +08:00
|
|
|
}
|
|
|
|
|
public static Quaternion RotationFromVector2(Vector2 dir)
|
|
|
|
|
{
|
|
|
|
|
float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
|
|
|
|
|
return Quaternion.Euler(0, 0, angle);
|
|
|
|
|
}
|
|
|
|
|
// 计算反射角度
|
|
|
|
|
Vector2 GetReflectionAngle(Vector2 velocity, Vector2 normal)
|
|
|
|
|
{
|
|
|
|
|
// 反射向量
|
|
|
|
|
return Vector2.Reflect(velocity.normalized, normal.normalized);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public void OnTriggerEnter2D(Collider2D collision)
|
|
|
|
|
{
|
|
|
|
|
if (isTriggerFirst)
|
|
|
|
|
{
|
|
|
|
|
if (collision.tag == "Fish")
|
|
|
|
|
{
|
|
|
|
|
isTriggerFirst = false;
|
|
|
|
|
var monster = collision.transform.GetComponentInParent<MonsterContral>();
|
|
|
|
|
|
|
|
|
|
AttackFish(monster);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (collision.tag == "Wall")
|
|
|
|
|
{
|
|
|
|
|
Vector3 v3 = transform.eulerAngles;
|
|
|
|
|
switch (collision.name)
|
|
|
|
|
{
|
|
|
|
|
case "up":
|
|
|
|
|
v3.z = -v3.z+180;
|
|
|
|
|
break;
|
|
|
|
|
case "down":
|
|
|
|
|
v3.z = -v3.z + 180;
|
|
|
|
|
break;
|
|
|
|
|
case "left":
|
|
|
|
|
v3.z = -v3.z;
|
|
|
|
|
break;
|
|
|
|
|
case "right":
|
|
|
|
|
v3.z = -v3.z;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vector3_startPosition = transform.position;
|
|
|
|
|
currShowTime = 0;
|
|
|
|
|
transform.eulerAngles = v3;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AttackFish(MonsterContral monster)
|
|
|
|
|
{
|
|
|
|
|
//击中特效
|
|
|
|
|
if (effectPrefab != null)
|
|
|
|
|
{
|
|
|
|
|
Instantiate(effectPrefab, transform.position, Quaternion.identity, transform.parent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//请求服务端是否杀死
|
|
|
|
|
var v1 = GameManager.Instance.gameData.roomJoinNotice;
|
|
|
|
|
var v2 = GameManager.Instance.gameData.currRoomData;
|
2026-02-09 10:44:38 +08:00
|
|
|
if (true)
|
|
|
|
|
{
|
2026-03-09 09:25:01 +08:00
|
|
|
WebSocketSendList.KillFish(v2.roomId, user.id,monster.monsterData.fishTypeConfig.fishNumber, monster.guid, GameManager.Instance.gameData.roomJoinNotice.cannonMultiple);
|
2026-02-09 10:44:38 +08:00
|
|
|
}
|
|
|
|
|
|
2026-02-03 11:35:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
//受激
|
|
|
|
|
|
|
|
|
|
//monster.monsterData.charactersHealth.OnHurt(10, CharacterHurtType.none);
|
|
|
|
|
//monster.HP--;
|
|
|
|
|
//if (monster.HP == 0)
|
|
|
|
|
//{
|
|
|
|
|
// Instantiate(monster.effect_Die == null ? diePrefab : monster.effect_Die, monster.transform.position, Quaternion.identity, transform.parent);
|
|
|
|
|
// Destroy(monster.gameObject);
|
|
|
|
|
//}
|
|
|
|
|
//else
|
|
|
|
|
//{
|
|
|
|
|
monster.OnHurt();
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
Destroy(gameObject);
|
2025-12-26 11:15:56 +08:00
|
|
|
}
|
|
|
|
|
}
|