Adding a way for the pick up to follow the Player

[SerializeField]
private float _followSpeed = 3f;
private bool _followPlayer = false;
private Player _player;
private void Start()
{
_player = GameObject.Find("Player").GetComponent<Player>();
if (_player == null)
{
Debug.Log("Player is null");
}
}
void Update()
{
if (!_followPlayer)
{
transform.Translate(Vector3.down * _speed * Time.deltaTime);
if (transform.position.y <= -6)
{
Destroy(gameObject);
}
}
else
{
Vector3 followDirection = (_player.transform.position - transform.position).normalized;
transform.Translate(followDirection * (_speed + _followSpeed) * Time.deltaTime);

}
}
public void OnEnable()
{
Player.CollectPickup += FollowPlayer;
}
private void OnDisable()
{
Player.CollectPickup -= FollowPlayer;
}
public static Action CollectPickup;void Update()
{
CalculateThruster();
CalculateMovement();
if (Input.GetKeyDown(KeyCode.Space) && CanFire())
{
FireLaser();
}
if (Input.GetKeyDown(KeyCode.C))
{
CollectPickup();
}

}

--

--

--

I love game design and development.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Retrofit/Volley

Serverless Project Code Structure for AWS Serverless E-Commerce Architecture

Recursion..(The Problem Solver)

Building a simple APM server | handling massive data writes and complex queries

Managing JWT Auth with Micronaut v2 (Part 2)

Who Can Win? ‘Map’, ‘Inject’ or ‘Eachs’?

Every DevOps engineer should know about 12-factor apps

Learn about QUEEN GAME!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jaime

Jaime

I love game design and development.

More from Medium

Making “Eyes” in Unity(Game Dev Day 61)

Op-Ed: How Ethical is Facial Recognition?

Introduction to ISLANDWAR Chain Tour

How to stick decals on the Spatial Mesh of Hololens2