You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
135 lines
4.0 KiB
135 lines
4.0 KiB
using UnityEngine; |
|
|
|
public enum GameObstaclesType |
|
{ |
|
BOX, |
|
HIGHT_BOX, |
|
SLOW_FLOOR, |
|
SPIKES_FLOOR, |
|
LASER, |
|
} |
|
|
|
public class GameObstacles : MonoBehaviour |
|
{ |
|
[SerializeField] GameObstaclesType m_type = GameObstaclesType.BOX; |
|
|
|
[SerializeField] float m_slowMult = 1f; |
|
[SerializeField] int m_spikesDamage = 0; |
|
[SerializeField] int m_laserDamage = 0; |
|
[SerializeField] float m_timeToDamage = 1f; |
|
|
|
GameObject m_activeLaserPart = null; |
|
|
|
[SerializeField] float m_leftLaserPos = -2.12f; |
|
[SerializeField] float m_rightLaserPos = 2.3f; |
|
[SerializeField] float m_laserMoveSpeed = 3f; |
|
|
|
bool m_moveLaserRight = false; |
|
bool m_moveLaserLeft = false; |
|
|
|
//----------------------------------------------------------------------------------------- |
|
public GameObstaclesType Type |
|
{ |
|
get { return m_type; } |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
public float SlowMult |
|
{ |
|
get { return m_slowMult; } |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
public float TimeToDamage |
|
{ |
|
get { return m_timeToDamage; } |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
public int SpikesDamage |
|
{ |
|
get { return m_spikesDamage; } |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
public int LaserDamage |
|
{ |
|
get { return m_laserDamage; } |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void Start () |
|
{ |
|
InitLaserParts(); |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void InitLaserParts() |
|
{ |
|
if (m_type != GameObstaclesType.LASER) |
|
return; |
|
|
|
Transform activePartTrans = transform.Find("active_laser_part"); |
|
if (activePartTrans) |
|
{ |
|
m_activeLaserPart = activePartTrans.gameObject; |
|
m_moveLaserRight = true; |
|
|
|
Vector3 scale = m_activeLaserPart.transform.localScale; |
|
scale.x = -scale.x; |
|
m_activeLaserPart.transform.localScale = scale; |
|
|
|
m_laserMoveSpeed += Random.Range(0.5f, 2); |
|
} |
|
else |
|
CommonFunctions.myassert(false); |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void Update () |
|
{ |
|
if (m_type == GameObstaclesType.LASER) |
|
UpdateActiveLaserPartMove(); |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void UpdateActiveLaserPartMove() |
|
{ |
|
if (m_moveLaserRight) |
|
{ |
|
Vector3 pos = m_activeLaserPart.transform.localPosition; |
|
pos.x += m_laserMoveSpeed * Time.deltaTime; |
|
m_activeLaserPart.transform.localPosition = pos; |
|
|
|
if (pos.x >= m_rightLaserPos) |
|
{ |
|
pos.x = m_rightLaserPos; |
|
m_activeLaserPart.transform.localPosition = pos; |
|
Vector3 scale = m_activeLaserPart.transform.localScale; |
|
scale.x = -scale.x; |
|
m_activeLaserPart.transform.localScale = scale; |
|
|
|
m_moveLaserRight = false; |
|
m_moveLaserLeft = true; |
|
} |
|
} |
|
else if (m_moveLaserLeft) |
|
{ |
|
Vector3 pos = m_activeLaserPart.transform.localPosition; |
|
pos.x -= m_laserMoveSpeed * Time.deltaTime; |
|
m_activeLaserPart.transform.localPosition = pos; |
|
|
|
if (pos.x <= m_leftLaserPos) |
|
{ |
|
pos.x = m_leftLaserPos; |
|
m_activeLaserPart.transform.localPosition = pos; |
|
Vector3 scale = m_activeLaserPart.transform.localScale; |
|
scale.x = -scale.x; |
|
m_activeLaserPart.transform.localScale = scale; |
|
|
|
m_moveLaserRight = true; |
|
m_moveLaserLeft = false; |
|
} |
|
} |
|
} |
|
}
|
|
|