This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Movement() | |
{ | |
transform.Translate(_direction * Time.deltaTime * _speed * _speedMultiplyer); | |
if (_isPlayerLaserSpawned == true) | |
{ | |
_playerLaser = FindObjectOfType<Laser>(); | |
if (_playerLaser != null) | |
{ | |
var laserPosition = _playerLaser.transform.position - transform.position; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Start() | |
{ | |
_player = GameObject.Find("Player").GetComponent<Player>(); | |
_explosionAudioObject = GameObject.Find("Explosion"); | |
if(_explosionAudioObject != null) | |
{ | |
_explosionSound = _explosionAudioObject.GetComponent<AudioSource>(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private float _speed = 4.0f; | |
private bool _isPlayerLaserSpawned = false; | |
private bool _fireLaser = true; | |
private Laser _playerLaser; | |
[SerializeField] | |
private GameObject _enemyLaser, _explosionObject; | |
private float _speedMultiplyer = 1.0f; | |
private Vector3 _direction = Vector3.down; | |
private Player _player; | |
private GameObject _explosionAudioObject; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void OnTriggerEnter2D(Collider2D collision) | |
{ | |
if (collision.tag == "Player") | |
{ | |
if (_player != null) | |
{ | |
_player.Damage(); | |
} | |
_speed = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Update() | |
{ | |
EnemyMovement(); | |
} | |
void EnemyMovement() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Start() | |
{ | |
Instantiate(_missile, transform.position, Quaternion.identity); | |
_playerObject = GameObject.Find("Player"); | |
if (_playerObject != null) | |
{ | |
_player = _playerObject.GetComponent<Player>(); | |
if (_player == null) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[SerializeField] | |
private GameObject _missile; | |
private Player _player; | |
private GameObject _playerObject; | |
private AudioSource _explosionSound; | |
private Animator _explosion; | |
private float _speed = 3.5f; | |
private Vector3 _direction = Vector3.right; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Missile Enemy | |
------------- | |
What do I need? | |
Missile Enemy Sprite | |
2D rigidbody | |
2D box collider | |
MissleEnemy script | |
Red Missile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void OnTriggerEnter2D(Collider2D collision) | |
{ | |
switch (collision.tag) | |
{ | |
case "Enemy": | |
Destroy(gameObject); | |
break; | |
case "Player": | |
Player _player = collision.transform.GetComponent<Player>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Movement() | |
{ | |
transform.Translate(Vector2.down * _speed * Time.deltaTime); | |
Vector3 direction = _playerLocation.transform.position - transform.position; | |
float rot_z = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; | |
transform.rotation = Quaternion.Euler(0f, 0f, rot_z + 90); | |
} |