Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class SimpleMove : MonoBehaviour {
- [SerializeField] GameObject score;
- [SerializeField] GameObject coin;
- int scoreAmount = 0;
- bool PickedUp = false;
- float timeSincePickup = 0f;
- private void Update()
- {
- if (PickedUp)
- {
- timeSincePickup += Time.deltaTime;
- }
- if (timeSincePickup >= 2f)
- {
- PickedUp = false;
- timeSincePickup = 0f;
- }
- if (Input.GetKey(KeyCode.D))
- {
- transform.position = transform.position + new Vector3(1f * Time.deltaTime, 0, 0);
- }
- if (Input.GetKey(KeyCode.A))
- {
- transform.position = transform.position + new Vector3(-1f * Time.deltaTime, 0, 0);
- }
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.name == "Coin")
- {
- scoreAmount++;
- score.GetComponent<Text>().text = "" + scoreAmount;
- Destroy(other.gameObject);
- StartCoroutine(AnimateScoreUI());
- }
- }
- IEnumerator AnimateScoreUI()
- {
- if (!PickedUp)
- {
- PickedUp = true;
- Vector3 sStart = new Vector3(0f, 30f, 0f);
- Vector3 sEnd = new Vector3(0, 0, 0);
- Vector3 cStart = new Vector3(20f, 30f, 0f);
- Vector3 cEnd = new Vector3(20f, 0f, 0f);
- bool done = false;
- float percent = 0f;
- while (!done)
- {
- percent += Time.deltaTime;
- score.transform.localPosition = Vector3.Lerp(sStart, sEnd, percent);
- coin.transform.localPosition = Vector3.Lerp(cStart, cEnd, percent);
- coin.transform.Rotate(Vector3.Lerp(coin.transform.rotation.eulerAngles, new Vector3(0f, 360f, 0f), percent));
- yield return new WaitForEndOfFrame();
- if (percent >= 1f)
- {
- done = true;
- }
- }
- while (PickedUp == true)
- {
- yield return new WaitForSeconds(1);
- }
- done = false;
- percent = 0f;
- while (!done)
- {
- percent += Time.deltaTime;
- score.transform.localPosition = Vector3.Lerp(sEnd, sStart, percent);
- coin.transform.localPosition = Vector3.Lerp(cStart, cEnd, percent);
- yield return new WaitForEndOfFrame();
- if (percent >= 1f)
- {
- done = true;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement