Schmup-JIN/Assets/Scripts/BasicShooter.cs
trotFunky 42706712aa Implemented shooting
Fixed abstract character not depleting energy when reaching zero
Created prefabs for player and enemy bullets
Added physics layers for players and enemies
2019-09-19 12:36:24 +02:00

29 lines
868 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BasicShooter : AbstractShooter
{
// Bullet that will be fired
[SerializeField] private GameObject _bullet;
private Transform _parentTransform;
// Direction the bullet will be going
[SerializeField] private Vector2 _direction = Vector2.right;
// Offset between parent and newly created bullet
[SerializeField] private Vector2 _offset = Vector2.zero;
void Start()
{
_parentTransform = GetComponentInParent<Transform>();
}
protected override void InstantiateProjectiles()
{
Vector3 newPosition = _parentTransform.position + (Vector3)_offset;
GameObject child = Instantiate(_bullet, newPosition, Quaternion.identity);
child.GetComponent<Bullet>().Direction = _direction;
}
}