116 lines
2.5 KiB
C#
116 lines
2.5 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Game
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2020-09-02
|
|||
|
// Description :
|
|||
|
// Last Modified By :
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "EntityPortal" company="Kimch"></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace G
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 传送门
|
|||
|
/// </summary>
|
|||
|
public class EntityPortal : Entity
|
|||
|
{
|
|||
|
private Transform _arrow;
|
|||
|
private float _openDelay;
|
|||
|
private Collider _collider;
|
|||
|
|
|||
|
public GameObject monsterFlag;
|
|||
|
public GameObject storyFlag;
|
|||
|
public GameObject bossFlag;
|
|||
|
|
|||
|
public static EntityPortal Instance;
|
|||
|
|
|||
|
public bool canOpen
|
|||
|
{
|
|||
|
get { return _collider.enabled; }
|
|||
|
}
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
_collider = GetComponent<Collider>();
|
|||
|
_arrow = transform.GetChild(0);
|
|||
|
_arrow.position = Vector3.one * 22f;
|
|||
|
}
|
|||
|
|
|||
|
private void OnEnable()
|
|||
|
{
|
|||
|
Instance = this;
|
|||
|
|
|||
|
_collider.enabled = false;
|
|||
|
_openDelay = 1.5f;
|
|||
|
string flag = name.Substring(5);
|
|||
|
if (int.TryParse(flag, out int stageId) && stageId > 0)
|
|||
|
{
|
|||
|
bossFlag.SetActive(false);
|
|||
|
var stage = ItemProxy.Instance.GetStaticItem<ItemStage>(stageId);
|
|||
|
if (stage.type == 3)
|
|||
|
{
|
|||
|
storyFlag.SetActive(true);
|
|||
|
monsterFlag.SetActive(false);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
storyFlag.SetActive(false);
|
|||
|
monsterFlag.SetActive(true);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
storyFlag.SetActive(false);
|
|||
|
monsterFlag.SetActive(false);
|
|||
|
if (flag == "boss")
|
|||
|
{
|
|||
|
bossFlag.SetActive(true);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void OnDisable()
|
|||
|
{
|
|||
|
Instance = null;
|
|||
|
}
|
|||
|
|
|||
|
private void OnTriggerEnter(Collider other)
|
|||
|
{
|
|||
|
if (other.name == "cha1")
|
|||
|
{
|
|||
|
this.gameObject.SetActive(false);
|
|||
|
_arrow.position = Vector3.one * 22f;
|
|||
|
EntityMainPlayer.Instance.EnterPortal(transform.position);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void Update()
|
|||
|
{
|
|||
|
if (_openDelay > 0f)
|
|||
|
{
|
|||
|
_openDelay -= Time.deltaTime;
|
|||
|
if (_openDelay <= 0f)
|
|||
|
{
|
|||
|
_collider.enabled = true;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
Vector3 vector = transform.position - EntityMainPlayer.Instance.position;
|
|||
|
if (vector.sqrMagnitude < 0.3f * 0.3f)
|
|||
|
{
|
|||
|
_arrow.position = Vector3.one * 22f;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
vector = vector.normalized;
|
|||
|
_arrow.rotation = Quaternion.LookRotation(vector);
|
|||
|
_arrow.position = EntityMainPlayer.Instance.position + Vector3.up * 0.02f + vector * 0.3f;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|