Skip to content

Instantly share code, notes, and snippets.

@curious-username
Last active December 30, 2021 02:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save curious-username/126ab6718685c0f979c3ea183a03cb14 to your computer and use it in GitHub Desktop.
Save curious-username/126ab6718685c0f979c3ea183a03cb14 to your computer and use it in GitHub Desktop.
powerup magnet
void Start()
{
_player = GameObject.Find("Player").GetComponent<Player>();
if(_player == null)
{
Debug.Log("Player Not Found");
}
}
void Update()
{
Movement();
}
private void Movement()
{
transform.Translate(_direction * _speed * Time.deltaTime * _speedMultiplier);
if(_player != null)
{
if (Input.GetKeyDown(KeyCode.C))
{
_direction = _player.transform.position - transform.position;
_speedMultiplier = 1.5f;
}
_speedMultiplier = 1.0f;
}
if (transform.position.y < -3.8f)
{
Destroy(this.gameObject);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment