private void Stamp(Vector2 from, Vector2 to)
        {
            // Main camera exists?
            var mainCamera = Camera.main;

            if (mainCamera != null)
            {
                if (from != to)
                {
                    var delta = to - from;

                    lastAngle = -Mathf.Atan2(delta.x, delta.y) * Mathf.Rad2Deg;
                }

                var positionA = D2dHelper.ScreenToWorldPosition(from, Intercept, mainCamera);
                var positionB = D2dHelper.ScreenToWorldPosition(to, Intercept, mainCamera);
                var positionM = (positionA + positionB) * 0.5f;
                var length    = Vector3.Distance(positionA, positionB) * Stretch;

                if (length < Size.y)
                {
                    length = Size.y;
                }

                var size = new Vector2(Size.x, length);

                // Stamp at that point
                D2dDestructible.StampAll(positionM, size, lastAngle, StampTex, Hardness, Layers);
            }
        }
        protected virtual void Start()
        {
            if (Stamp == true)
            {
                var stampPosition = transform.position;
                var stampAngle    = StampRandomDirection == true?Random.Range(-180.0f, 180.0f) : 0.0f;



                D2dDestructible.StampAll(stampPosition, StampSize, stampAngle, StampTex, StampHardness, Mask);
            }

            if (Raycast == true && RaycastCount > 0)
            {
                var angleStep = 360.0f / RaycastCount;

                for (var i = 0; i < RaycastCount; i++)
                {
                    var angle     = i * angleStep;
                    var direction = new Vector2(Mathf.Sin(angle), Mathf.Cos(angle));
                    var hit       = Physics2D.Raycast(transform.position, direction, RaycastRadius, Mask);
                    var collider  = hit.collider;

                    // Make sure the raycast hit something, and that it wasn't a trigger
                    if (collider != null && collider.isTrigger == false)
                    {
                        var strength = 1.0f - hit.fraction;                         // Do less damage if the hit point is far from the explosion

                        // Add damage?
                        if (DamagePerRay != 0.0f)
                        {
                            var destructible = collider.GetComponentInParent <D2dDestructible>();

                            if (destructible != null)
                            {
                                destructible.Damage += DamagePerRay * strength;
                            }
                        }

                        // Add force?
                        if (ForcePerRay != 0.0f)
                        {
                            var rigidbody2D = collider.attachedRigidbody;

                            if (rigidbody2D != null)
                            {
                                var force = direction * ForcePerRay * strength;

                                rigidbody2D.AddForceAtPosition(force, hit.point);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        protected virtual void Update()
        {
            if (Input.GetMouseButton(0) && Camera.main != null)
            {
                var ray      = Camera.main.ScreenPointToRay(Input.mousePosition);
                var distance = D2dHelper.Divide(ray.origin.z, ray.direction.z);
                var point    = ray.origin - ray.direction * distance;

                D2dDestructible.StampAll(point, Size, Angle, StampTex, Hardness, Layers);
            }
        }
Esempio n. 4
0
        protected virtual void Update()
        {
            cooldown -= Time.deltaTime;

            if (cooldown <= 0.0f)
            {
                cooldown = Delay;

                var angle = Random.Range(0.0f, 360.0f);

                D2dDestructible.StampAll(transform.position, Size, angle, StampTex, Hardness, Layers);
            }
        }
Esempio n. 5
0
        protected virtual void Update()
        {
            // Required key is down?
            if (Input.GetKeyDown(Requires) == true)
            {
                // Main camera exists?
                var mainCamera = Camera.main;

                if (mainCamera != null)
                {
                    // World position of the mouse
                    var position = D2dHelper.ScreenToWorldPosition(Input.mousePosition, mainCamera);

                    // Stamp at that point
                    D2dDestructible.StampAll(position, Size, Angle, StampTex, Hardness, Layers);
                }
            }
        }
Esempio n. 6
0
        protected virtual void Update()
        {
            // 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
                    var ray = mainCamera.ScreenPointToRay(Input.mousePosition);

                    // Project ray onto Z=0 plane and find the point it intersects
                    var distance = D2dHelper.Divide(ray.origin.z, ray.direction.z);
                    var point    = ray.origin - ray.direction * distance;

                    // Stamp at that point
                    D2dDestructible.StampAll(point, Size, Angle, StampTex, Hardness, Layers);
                }
            }
        }
Esempio n. 7
0
 public void ForceStamp()
 {
     //var angle = Random.Range(0.0f, 360.0f);
     D2dDestructible.StampAll(transform.position, Size, 0, StampTex, Hardness, Layers);
 }
        protected virtual void Start()
        {
            float radius = 3;
            float damage = 25;

            RaycastHit2D[] objectsInRange = Physics2D.CircleCastAll(transform.position, radius, Vector2.zero);
            foreach (RaycastHit2D col in objectsInRange)
            {
                Health health = col.collider.GetComponent <Health>();
                if (health != null)
                {
                    //Linear falloff of effect
                    float proximity = (col.transform.position - transform.position).magnitude;
                    float effect    = 0.5f + (0.5f * ((radius - proximity) / radius));
                    //Put this value into a variable
                    damage = damage * effect;

                    int damageInt = (int)damage;
                    health.ApplyDamage(damageInt);
                }
            }

            if (Stamp == true)
            {
                var stampPosition = transform.position;
                var stampAngle    = StampRandomDirection == true?Random.Range(-180.0f, 180.0f) : 0.0f;

                D2dDestructible.StampAll(stampPosition, StampSize, stampAngle, StampTex, StampHardness, Mask);
            }

            if (Raycast == true && RaycastCount > 0)
            {
                var angleStep = 360.0f / RaycastCount;

                // Add damage?
                if (DamagePerRay != 0.0f)
                {
                    for (var i = 0; i < RaycastCount; i++)
                    {
                        var angle     = i * angleStep;
                        var direction = new Vector2(Mathf.Sin(angle), Mathf.Cos(angle));
                        var hit       = Physics2D.Raycast(transform.position, direction, RaycastRadius, Mask);
                        var collider  = hit.collider;

                        // Make sure the raycast hit something, and that it wasn't a trigger
                        if (collider != null && collider.isTrigger == false)
                        {
                            var strength     = 1.0f - hit.fraction;                             // Do less damage if the hit point is far from the explosion
                            var destructible = collider.GetComponentInParent <D2dDestructible>();

                            if (destructible != null)
                            {
                                destructible.Damage += DamagePerRay * strength;
                            }
                        }
                    }
                }

                // Add force?
                if (ForcePerRay != 0.0f)
                {
                    for (var i = 0; i < RaycastCount; i++)
                    {
                        var angle     = i * angleStep;
                        var direction = new Vector2(Mathf.Sin(angle), Mathf.Cos(angle));
                        var hit       = Physics2D.Raycast(transform.position, direction, RaycastRadius, Mask);
                        var collider  = hit.collider;

                        // Make sure the raycast hit something, and that it wasn't a trigger
                        if (collider != null && collider.isTrigger == false)
                        {
                            var strength    = 1.0f - hit.fraction;                             // Do less damage if the hit point is far from the explosion
                            var rigidbody2D = collider.attachedRigidbody;

                            if (rigidbody2D != null)
                            {
                                var force = direction * ForcePerRay * strength;

                                rigidbody2D.AddForceAtPosition(force, hit.point);
                            }
                        }
                    }
                }
            }
        }