protected virtual void OnEnable() { if (cachedDestructible == null) { cachedDestructible = GetComponent <D2dDestructible>(); } }
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, Intercept, mainCamera); // Read the destructible and alpha at this position var destructible = default(D2dDestructible); var alpha = default(Color32); if (D2dDestructible.TrySampleAlphaAll(position, ref destructible, ref alpha) == true) { Debug.Log("Read " + destructible + " with alpha: " + alpha); } else { Debug.Log("Read nothing."); } } } }
protected virtual void Update() { // Touching the screen? inputManager.Update(Requires); if (inputManager.Fingers.Count > 0) { // Main camera exists? var mainCamera = Camera.main; if (mainCamera != null) { // World position of the mouse var position = D2dHelper.ScreenToWorldPosition(inputManager.Fingers[0].PositionA, Intercept, mainCamera); // Read the destructible and alpha at this position var destructible = default(D2dDestructible); var alpha = default(Color32); if (D2dDestructible.TrySampleAlphaAll(position, ref destructible, ref alpha) == true) { Debug.Log("Read " + destructible + " with alpha: " + alpha); } else { Debug.Log("Read nothing."); } } } }
private void OnTriggerEnter2D(Collider2D collision) { if (Layers == (Layers | (1 << collision.gameObject.layer))) { D2dDestructible.StampAll(transform.position, Size * transform.localScale, Angle, StampTex, Hardness, Layers); Destroy(gameObject); } if (transform.gameObject.tag == "bombe1") { if (collision.gameObject.tag == "tank2") { Destroy(collision.gameObject); Destroy(gameObject); Instantiate(victory); } } else if (transform.gameObject.tag == "bombe2") { if (collision.gameObject.tag == "tank1") { Destroy(collision.gameObject); Destroy(gameObject); Instantiate(victory); } } }
private void DropOutBG(List <Line> circleLines) { foreach (var line in circleLines) { D2dDestructible.SliceAll(line.Nodes[0].transform.position, line.Nodes[1].transform.position, 0.2f, stampTax, 10); Destroy(line.gameObject); } }
// Update is called once per frame void Update() { laserShowTime -= Time.deltaTime; var pos = transform.position; var dir = new Vector3(laserDistLength, 0, 0); dir = transform.rotation * dir; var endPoint = pos + dir; if (Input.GetKeyUp(KeyCode.L) || player.GetButtonUp("B")) { laserShowTime = laserTime; } var lineRenderer = gameObject.GetComponent <LineRenderer> (); if (laserShowTime > 0.0f) { destruct++; if (destruct > destructPerFrame) { destruct = 0; var mainCamera = Camera.main; Debug.Log("LASER! PEW PEW"); Debug.Log("XY: " + pos.x + ", " + pos.y); Debug.Log("XY: " + endPoint.x + ", " + endPoint.y); // var startPos = D2dHelper.ScreenToWorldPosition(pos, 0, mainCamera); // var endPos = D2dHelper.ScreenToWorldPosition(endPoint, 0, mainCamera); D2dDestructible.SliceAll(pos, endPoint, Thickness, StampTex, Hardness); RaycastHit2D[] raycastHit2ds = Physics2D.RaycastAll(pos, (endPoint - pos).normalized, Vector2.Distance(endPoint, pos)); foreach (RaycastHit2D raycastHit2d in raycastHit2ds) { Villager villager = raycastHit2d.collider.gameObject.GetComponent <Villager>(); if (villager != null) { villager.Die(); } } } lineRenderer.enabled = true; lineRenderer.SetPositions( new Vector3[] { pos, endPoint } ); } else { lineRenderer.enabled = false; } }
protected virtual void OnEnable() { if (cachedDestructible == null) { cachedDestructible = GetComponent <D2dDestructible>(); } cachedDestructible.OnSplitEnd += HandleSplitEnd; }
private void OnMelt(Collider2D col) { IEnumerable <Vector2> points = GetPointsInRange(col); foreach (var point in points) { Instantiate(_steam, point, new Quaternion()); D2dDestructible.StampAll(point, Vector2.one * col.gameObject.GetComponent <HeatHandler>().HeatMessage.Intensity / 100, 0, _stampTex, 1, 1 << LayerMask.NameToLayer(Layers.Ice) | 1 << LayerMask.NameToLayer(Layers.BackgroundIce)); } }
private void Awake() { if (entities == null) { entities = new List <Entity>(); } entities.Add(this); Spawned++; rb = GetComponent <Rigidbody2D>(); destructible = GetComponent <D2dDestructible>(); }
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); } } } } } }
private void OnTriggerEnter2D(Collider2D collision) { if (Layers == (Layers | (1 << collision.gameObject.layer))) { D2dDestructible.StampAll(transform.position, Size * transform.localScale, Angle, StampTex, Hardness, Layers); Transform instance = Instantiate(explode, transform.position, transform.rotation); instance.localScale = transform.localScale * Size; Destroy(instance.gameObject, 1); for (int i = 0; i < nbFragmentation; i++) { float dir = Random.Range(0, 180); if (dir < 90) { dir = 360 - dir; } else { dir -= 90; } Transform newBombe = Instantiate(bombe, transform.position, transform.rotation); newBombe.localScale = transform.localScale / 2; newBombe.GetComponent <Rigidbody2D>().velocity = Quaternion.Euler(0, 0, dir) * rb.velocity; Destroy(newBombe.gameObject, 1); } SoundControler._soundControler.PlaySound(SoundControler._soundControler._bomb); Destroy(gameObject); } if (transform.name == "bombe1") { if (collision.gameObject.tag == "tank2") { Destroy(collision.gameObject); Destroy(gameObject); Instantiate(victory); } } else if (transform.name == "bombe2") { if (collision.gameObject.tag == "tank1") { Destroy(collision.gameObject); Destroy(gameObject); Instantiate(victory); } } }
protected virtual void OnEnable() { if (cachedDestructible == null) { cachedDestructible = GetComponent <D2dDestructible>(); } if (cachedRigidbody2D == null) { cachedRigidbody2D = GetComponent <Rigidbody2D>(); } cachedDestructible.OnSplitStart += HandleSplitStart; cachedDestructible.OnSplitEnd += HandleSplitEnd; }
// Use this for initialization void Start() { if (!OnlySound) { var circle = GetComponent <CircleCollider2D>(); //stamp float radius = circle.radius * ((transform.localScale.x + transform.localScale.y + transform.localScale.z) / 3f); D2dDestructible.StampAll(transform.position, new Vector2(radius, radius) * 2f, transform.localEulerAngles.z, Stamp, 1f); //end stamp //circlecast RaycastHit2D[] results = Physics2D.CircleCastAll(transform.position, radius, Vector2.zero, 0f); DamageTargets(results); } if (SoundNames.Count != 0) { MasterAudioSummoner.instance.PlayAudio(MasterAudioSummoner.instance.ExplosionSounds, SoundNames[Random.Range(0, SoundNames.Count)], 1f, 0.1f, transform.position, null); } }
// Use this for initialization protected override void Start() { base.Start(); _DestructibleSprite = GetComponent <D2dDestructible>(); _AutoCollider = GetComponent <D2dAutoCollider>(); _RotationAngle = Random.Range(0f, 45f); _Speed = Random.Range(-1, -10); _Rigidbody.AddTorque(_Rigidbody.mass * _RotationAngle); _Rigidbody.AddForce(new Vector2(_Rigidbody.mass * _Speed, _Rigidbody.position.y), ForceMode2D.Force); _Health = Mathf.FloorToInt((float)_DestructibleSprite.AlphaCount / 100); _Damage = Mathf.FloorToInt((float)_DestructibleSprite.AlphaCount / 100); _Integrality = Mathf.FloorToInt(((float)_DestructibleSprite.AlphaCount / (float)_DestructibleSprite.OriginalAlphaCount) * 100); //_Magnitude = _Rigidbody.velocity.magnitude; if (_Integrality < 1) { Destroy(gameObject); } }
void Detonate() { gameManager = GameObject.Find("GameManager").GetComponent <GameManager>(); D2dDestructible.StampAll(transform.position, new Vector2(1, 1) * explosionSize, 0f, stamp, 1); List <Player> players = GameObject.Find("GameManager").GetComponent <GameManager>().Players; foreach (Player player in players) { if (Vector2.Distance(player.transform.position, transform.position) < 2f) { int damage = Mathf.RoundToInt((1f - (Vector2.Distance(player.transform.position, transform.position) / 2f)) * damageCaused); gameManager.RegisterDamage(player, damage); player.attacked = true; player.GetComponent <Animator>().SetTrigger("attacked"); player.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeRotation; Vector2 throwDirection = player.transform.position - transform.position; throwDirection.y = 1; player.GetComponent <Rigidbody2D>().velocity = throwDirection * (damage / 20f); } } Destroy(gameObject); }
private void Melt(HeatMessage message, Collider2D col) { if (timer > 0.25f) { timer = 0; } //if (Random.value < message.Intensity / 100) if (timer == 0) { IEnumerable <Vector2> points = GetPointsInRange(col); foreach (var point in points) { D2dDestructible.StampAll(point, Vector2.one * StampSize, 0, StampTex, 1, 1 << LayerMask.NameToLayer(Layers.Ice)); } //_polyCollider.points = MovePointsInwards(col); //_polyCollider.points = FlattenAngles(); //SetMeshFilterToPolyColliderPoints(); } timer += Time.deltaTime; }
// Use this for initialization void Start() { d = GetComponent <D2dDestructible> (); }
protected virtual void Update() { // Update input inputManager.Update(Requires); // Make sure the camera exists var camera = D2dHelper.GetCamera(null); if (camera != null) { // Loop through all non-gui fingers foreach (var finger in inputManager.Fingers) { if (finger.StartedOverGui == false) { // Grab extra finger data and position var link = D2dInputManager.Link.FindOrCreate(ref links, finger); var position = D2dHelper.ScreenToWorldPosition(finger.PositionA, Intercept, camera); // Create indiactor? if (finger.Down == true && IndicatorPrefab != null) { link.Visual = Instantiate(IndicatorPrefab); link.Scale = link.Visual.transform.localScale; link.Visual.SetActive(true); } // Update indicator? if (finger.Set == true && link.Visual != null) { link.Visual.transform.position = position; link.Visual.transform.localScale = Vector3.Scale(link.Scale, new Vector3(Size.x, Size.y, 1.0f)); } // Clear indicator then stamp? if (finger.Up == true) { // Stamp everything at this point? if (Hit == HitType.All) { D2dStamp.All(Paint, position, Size, Angle, Shape, Color, Layers); } // Stamp the first thing at this point? if (Hit == HitType.First) { var destructible = default(D2dDestructible); if (D2dDestructible.TrySampleThrough(position, ref destructible) == true) { destructible.Paint(Paint, D2dStamp.CalculateMatrix(position, Size, Angle), Shape, Color); } } // Destroy indicator link.Clear(); } } } } }
protected virtual void Update() { // Main camera exists? var mainCamera = Camera.main; if (mainCamera != null) { // World position of the mouse var position = D2dHelper.ScreenToWorldPosition(Input.mousePosition, Intercept, mainCamera); // Begin dragging if (Input.GetKey(Requires) == true && down == false) { down = true; } // End dragging if (Input.GetKey(Requires) == false && down == true) { down = false; // Stamp everything at this point? if (Hit == HitType.All) { D2dStamp.All(Paint, position, Size, Angle, Shape, Color, Layers); } // Stamp the first thing at this point? if (Hit == HitType.First) { var destructible = default(D2dDestructible); if (D2dDestructible.TrySampleThrough(position, ref destructible) == true) { destructible.Paint(Paint, D2dStamp.CalculateMatrix(position, Size, Angle), Shape, Color); } } } // Update indicator? if (down == true && IndicatorPrefab != null) { if (indicatorInstance == null) { indicatorInstance = Instantiate(IndicatorPrefab); indicatorScale = indicatorInstance.transform.localScale; indicatorInstance.SetActive(true); } indicatorInstance.transform.position = position; indicatorInstance.transform.localScale = Vector3.Scale(indicatorScale, new Vector3(Size.x, Size.y, 1.0f)); } // Destroy indicator? else if (indicatorInstance != null) { Destroy(indicatorInstance.gameObject); } } }