| | | 1 | | using System.Collections; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using TMPro; |
| | | 4 | | using Unity.VisualScripting; |
| | | 5 | | using UnityEditor; |
| | | 6 | | using UnityEngine; |
| | | 7 | | using UnityEngine.Events; |
| | | 8 | | using UnityEngine.ProBuilder.Shapes; |
| | | 9 | | using UnityEngine.WSA; |
| | | 10 | | |
| | | 11 | | public class PlatformMovement : MonoBehaviour |
| | | 12 | | { |
| | | 13 | | [Header("Game Object Components")] |
| | | 14 | | [SerializeField] GameObject[] wayPoints; |
| | 4 | 15 | | int indexWayPoint = 0; |
| | 4 | 16 | | public float platformSpeed = 2f; |
| | | 17 | | |
| | | 18 | | [Header("UI Components")] |
| | | 19 | | [SerializeField] Canvas congratulationsUI; |
| | | 20 | | [SerializeField] Canvas gemsChildUI; |
| | 4 | 21 | | int total = 0; |
| | | 22 | | [SerializeField] TMP_Text gemsValueUI; |
| | | 23 | | |
| | | 24 | | private void Start() |
| | 2 | 25 | | { |
| | 2 | 26 | | congratulationsUI.enabled = false; |
| | 2 | 27 | | gemsChildUI.enabled = false; |
| | 2 | 28 | | } |
| | | 29 | | |
| | 6201 | 30 | | void Update() { MovePlatform(); } |
| | | 31 | | |
| | | 32 | | void MovePlatform() |
| | 2067 | 33 | | { |
| | 2067 | 34 | | if (Vector3.Distance(transform.position, wayPoints[indexWayPoint].transform.position) < 0.1f) |
| | 4 | 35 | | { |
| | 4 | 36 | | indexWayPoint++; |
| | | 37 | | |
| | 4 | 38 | | if (indexWayPoint >= wayPoints.Length) |
| | 1 | 39 | | { |
| | 1 | 40 | | indexWayPoint = 0; |
| | 1 | 41 | | } |
| | 4 | 42 | | } |
| | 2067 | 43 | | transform.position = Vector3.MoveTowards(transform.position, wayPoints[indexWayPoint].transform.position, platfo |
| | 2067 | 44 | | } |
| | | 45 | | |
| | | 46 | | // nos da la colision con la cual colisiono el objeto |
| | | 47 | | private void OnCollisionEnter(Collision collision) |
| | 0 | 48 | | { |
| | 0 | 49 | | if (collision.gameObject.CompareTag("Gems")) |
| | 0 | 50 | | { |
| | 0 | 51 | | collision.gameObject.transform.SetParent(transform, true); |
| | 0 | 52 | | collision.transform.SetParent(transform, true); |
| | | 53 | | //collision.rigidbody.Sleep(); |
| | | 54 | | |
| | 0 | 55 | | getFiftyPoints(); |
| | 0 | 56 | | } |
| | 0 | 57 | | } |
| | | 58 | | |
| | | 59 | | public void getFiftyPoints() |
| | 5 | 60 | | { |
| | 5 | 61 | | total += 10; |
| | 5 | 62 | | gemsChildUI.enabled = true; |
| | 5 | 63 | | gemsValueUI.text = $" Score:{total}"; |
| | 5 | 64 | | if (total == 50) |
| | 1 | 65 | | { |
| | 1 | 66 | | congratulationsUI.enabled = true; |
| | 1 | 67 | | } |
| | 5 | 68 | | } |
| | | 69 | | } |