protected virtual void Update()
        {
            // Get the main camera?
            if (mainCamera == null)
            {
                mainCamera = Camera.main;
            }

            if (Input.GetKeyDown(Requires) == true)
            {
                if (mainCamera != null)
                {
                    var screenPoint = Input.mousePosition;
                    var worldPoint  = Camera.main.ScreenToWorldPoint(screenPoint);
                    var collider    = Physics2D.OverlapPoint(worldPoint);

                    if (collider != null)
                    {
                        var destructible = collider.GetComponentInParent <D2dDestructible>();

                        if (destructible != null)
                        {
                            D2dQuadFracturer.Fracture(destructible, FractureCount, 0.5f, 1);

                            if (ExplosionPrefab != null)
                            {
                                var worldRotation = Quaternion.Euler(0.0f, 0.0f, Random.Range(0.0f, 360.0f));                                 // Random rotation around Z axis

                                Instantiate(ExplosionPrefab, worldPoint, worldRotation);
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
        protected virtual void Update()
        {
            if (FractureCount <= 0)
            {
                return;
            }

            // Required key is down?
            if (Input.GetKeyDown(Requires) == true)
            {
                // Main camera exists?
                var mainCamera = Camera.main;

                if (mainCamera != null)
                {
                    // Get screen ray of mouse position
                    explosionPosition = D2dHelper.ScreenToWorldPosition(Input.mousePosition, Intercept, mainCamera);

                    var collider = Physics2D.OverlapPoint(explosionPosition);

                    if (collider != null)
                    {
                        var destructible = collider.GetComponentInParent <D2dDestructible>();

                        if (destructible != null)
                        {
                            // Register split event
                            destructible.OnEndSplit.AddListener(OnEndSplit);

                            // Split via fracture
                            D2dQuadFracturer.Fracture(destructible, FractureCount, 0.5f);

                            // Unregister split event
                            destructible.OnEndSplit.RemoveListener(OnEndSplit);

                            // Spawn explosion prefab?
                            if (ExplosionPrefab != null)
                            {
                                var worldRotation = Quaternion.Euler(0.0f, 0.0f, Random.Range(0.0f, 360.0f));                                 // Random rotation around Z axis

                                Instantiate(ExplosionPrefab, explosionPosition, worldRotation);
                            }
                        }
                    }
                }
            }
        }