| | | 1 | | using System.Collections; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using UnityEngine; |
| | | 4 | | |
| | | 5 | | |
| | | 6 | | public class PlatformController : MonoBehaviour |
| | | 7 | | { |
| | | 8 | | [SerializeField] private Vector3 arcPosition; |
| | | 9 | | [SerializeField] private GameObject arcPrefab; |
| | | 10 | | [SerializeField] private int numberOfPlatform; |
| | | 11 | | [SerializeField] private Vector3 rotation; |
| | | 12 | | |
| | | 13 | | private static int numberCorrectCube; |
| | | 14 | | private static bool arcDroped; |
| | | 15 | | private Quaternion arcRotation; |
| | | 16 | | // Start is called before the first frame update |
| | | 17 | | void Awake() |
| | 24 | 18 | | { |
| | 24 | 19 | | numberCorrectCube = 0; |
| | 24 | 20 | | arcDroped = false; |
| | 24 | 21 | | arcRotation = Quaternion.Euler(rotation); |
| | 24 | 22 | | } |
| | | 23 | | |
| | | 24 | | private void OnCollisionEnter(Collision collision) //Un appel par collision, donc si l'objet touche 6 autres objets, |
| | 15 | 25 | | { |
| | | 26 | | |
| | 15 | 27 | | if (collision.gameObject.layer == LayerMask.NameToLayer("ColoredCube")) |
| | 15 | 28 | | { |
| | 15 | 29 | | if (collision.gameObject.GetComponent<Renderer>().sharedMaterial == this.gameObject.GetComponent<Renderer>() |
| | | 30 | | |
| | 8 | 31 | | { |
| | 8 | 32 | | numberCorrectCube++; |
| | 8 | 33 | | if (numberCorrectCube == numberOfPlatform) |
| | 0 | 34 | | { |
| | 0 | 35 | | Instantiate(arcPrefab, arcPosition, arcRotation); |
| | 0 | 36 | | arcDroped = true; |
| | 0 | 37 | | } |
| | 8 | 38 | | } |
| | 15 | 39 | | } |
| | 15 | 40 | | } |
| | | 41 | | |
| | | 42 | | private void OnCollisionExit(Collision collision) |
| | 11 | 43 | | { |
| | 11 | 44 | | if (collision.gameObject.layer == LayerMask.NameToLayer("ColoredCube")) |
| | 11 | 45 | | { |
| | 11 | 46 | | if (collision.gameObject.GetComponent<Renderer>().sharedMaterial == this.gameObject.GetComponent<Renderer>() |
| | | 47 | | |
| | 7 | 48 | | { |
| | 7 | 49 | | numberCorrectCube--; |
| | 7 | 50 | | } |
| | 11 | 51 | | } |
| | 11 | 52 | | } |
| | | 53 | | |
| | | 54 | | } |