Adam Ramberg e4c489c88e WIP
2020-03-11 21:11:27 +01:00

49 lines
1.3 KiB
C#

using UnityAtoms.BaseAtoms;
using UnityEngine;
public class PlayerShooting : MonoBehaviour
{
[SerializeField]
private GameObject _projectile;
[SerializeField]
private StringConstant _playerTag;
void Update()
{
var shootDirection = Vector3.zero;
var rot = Quaternion.identity;
if (Input.GetKeyDown(KeyCode.UpArrow))
{
shootDirection = Vector3.up;
rot = Quaternion.Euler(0f, 0f, 90f);
}
else if (Input.GetKeyDown(KeyCode.DownArrow))
{
shootDirection = Vector3.down;
rot = Quaternion.Euler(0f, 0f, -90f);
}
else if (Input.GetKeyDown(KeyCode.RightArrow))
{
shootDirection = Vector3.right;
rot = Quaternion.Euler(0f, 0f, 0f);
}
else if (Input.GetKeyDown(KeyCode.LeftArrow))
{
shootDirection = Vector3.left;
rot = Quaternion.Euler(0f, 0f, 180f);
}
if (shootDirection != Vector3.zero)
{
var spawnPos = transform.position + shootDirection * 0.6f;
var projectile = Instantiate(_projectile, spawnPos, rot);
projectile.GetComponent<DecreaseHealth>().TagsAffected.Remove(_playerTag); // Turn off friendly fire
}
}
}