Last active
December 30, 2021 02:57
-
-
Save curious-username/126ab6718685c0f979c3ea183a03cb14 to your computer and use it in GitHub Desktop.
powerup magnet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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