1
0
Fork 0
Bildschirmflausch-LD41/Assets/Scripts/Entities/Player.cs

79 lines
2.2 KiB
C#
Raw Normal View History

using Assets.Scripts.Entities.Attack;
using UnityEngine;
public class Player : Mob {
[SerializeField]
private GameObject bulletPrefab;
[SerializeField]
Transform bulletSpawn;
2018-04-23 19:50:04 +02:00
//[SerializeField]
//private int carDamage = 5;
2018-04-23 18:38:43 +02:00
private SingleShot singleShot;
private GatlingGun ggun;
private float nextAttackTime;
public Player() : base(100) { }
private void Start() {
SingleShot s = new SingleShot(this.gameObject);
s.SetPrefab(bulletPrefab);
s.SetSpawn(bulletSpawn);
2018-04-23 18:38:43 +02:00
singleShot = s;
GatlingGun g = new GatlingGun(this.gameObject);
g.SetPrefab(bulletPrefab);
g.SetSpawn(bulletSpawn);
ggun = g;
SetAttack(s);
}
void Update() {
2018-04-23 18:38:43 +02:00
if(Input.GetKeyDown(KeyCode.G)) {
if(attack != ggun) {
attack = ggun;
Debug.Log("Switched to GatlingGun");
} else {
attack = singleShot;
Debug.Log("Switched to SingleShot");
}
}
if ( Time.timeSinceLevelLoad >= nextAttackTime && attack != null) {
if ( Input.GetAxis("Fire") > 0 ) {
Debug.Log("Attack pressed!");
attack.Attack();
nextAttackTime = Time.timeSinceLevelLoad + attack.GetCooldownTime();
}
}
}
/// <summary>
/// Collision checking. Player is going to die on any collision with a wall.
/// </summary>
/// <param name="collision"></param>
private void OnCollisionEnter2D(Collision2D collision) {
2018-04-21 19:50:12 +02:00
Debug.Log("Collision");
if ( collision.collider.tag == "wall" ) {
Death();
2018-04-23 01:25:50 +02:00
} else if ( collision.collider.tag == "Enemy" ) {
Mob m = collision.collider.GetComponent(typeof(Mob)) as Mob;
if ( m != null ) {
2018-04-23 01:25:50 +02:00
//m.InflictDamage(carDamage);
//InflictDamage(carDamage); // TODO
}
2018-04-21 19:50:12 +02:00
}
}
2018-04-21 19:50:12 +02:00
/// <summary>
/// This is called when a Player died.
/// </summary>
protected override void Death() {
Debug.Log("Player died...");
2018-04-21 19:50:12 +02:00
Destroy(this.gameObject);
2018-04-22 00:22:56 +02:00
GameController.instance.ChangeState(GameController.GameState.ENDED);
}
}