protected virtual void Update() { // Required key is down? if (Input.GetKeyDown(Requires) == true) { // Prefab exists? if (Prefab != null) { // Main camera exists? var mainCamera = Camera.main; if (mainCamera != null) { // World position of the mouse var position = D2dHelper.ScreenToWorldPosition(Input.mousePosition, Intercept, mainCamera); // Get a random rotation around the Z axis var rotation = Quaternion.Euler(0.0f, 0.0f, Random.Range(0.0f, 360.0f)); // Spawn prefab here Instantiate(Prefab, position, rotation); } } } }
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 Update() { // Get main camera var mainCamera = Camera.main; // Begin dragging if (Input.GetKey(Requires) == true && down == false) { down = true; startMousePosition = Input.mousePosition; } // Dragging finger released? if (Input.GetKey(Requires) == false && down == true) { down = false; // Impact prefab exists? if (ImpactPrefab != null) { // Main camera exists? if (mainCamera != null) { // Find start and end world points var startPos = D2dHelper.ScreenToWorldPosition(startMousePosition, Intercept); var endPos = D2dHelper.ScreenToWorldPosition(Input.mousePosition, Intercept); // Extend end pos to raycast hit CalculateEndPos(startPos, ref endPos); // Spawn explosion there Instantiate(ImpactPrefab, endPos, Quaternion.identity); } } } // Update indicator? if (down == true && mainCamera != null && IndicatorPrefab != null) { if (indicatorInstance == null) { indicatorInstance = Instantiate(IndicatorPrefab); } var startPos = D2dHelper.ScreenToWorldPosition(startMousePosition, Intercept); var endPos = D2dHelper.ScreenToWorldPosition(Input.mousePosition, Intercept); CalculateEndPos(startPos, ref endPos); var scale = Vector3.Distance(endPos, startPos); var angle = D2dHelper.Atan2(endPos - startPos) * Mathf.Rad2Deg; // Transform the indicator so it lines up with the slice indicatorInstance.transform.position = startPos; indicatorInstance.transform.rotation = Quaternion.Euler(0.0f, 0.0f, -angle); indicatorInstance.transform.localScale = new Vector3(Thickness, scale, scale); } // Destroy indicator? else if (indicatorInstance != null) { Destroy(indicatorInstance.gameObject); } }
protected virtual void Update() { // Get the main camera var mainCamera = Camera.main; // Begin dragging if (Input.GetKey(Requires) == true && down == false) { down = true; startMousePosition = Input.mousePosition; } // End dragging if (Input.GetKey(Requires) == false && down == true) { down = false; // Main camera exists? if (mainCamera != null) { var endMousePosition = Input.mousePosition; var startPos = D2dHelper.ScreenToWorldPosition(startMousePosition, Intercept, mainCamera); var endPos = D2dHelper.ScreenToWorldPosition(endMousePosition, Intercept, mainCamera); D2dSlice.All(Paint, startPos, endPos, Thickness, Shape, Color, Layers); } } // Update indicator? if (down == true && mainCamera != null && IndicatorPrefab != null) { if (indicatorInstance == null) { indicatorInstance = Instantiate(IndicatorPrefab); } var startPos = D2dHelper.ScreenToWorldPosition(startMousePosition, Intercept, mainCamera); var currentPos = D2dHelper.ScreenToWorldPosition(Input.mousePosition, Intercept, mainCamera); var scale = Vector3.Distance(currentPos, startPos); var angle = D2dHelper.Atan2(currentPos - startPos) * Mathf.Rad2Deg; // Transform the indicator so it lines up with the slice indicatorInstance.transform.position = startPos; indicatorInstance.transform.rotation = Quaternion.Euler(0.0f, 0.0f, -angle); indicatorInstance.transform.localScale = new Vector3(Thickness, scale, scale); } // Destroy indicator? else if (indicatorInstance != null) { Destroy(indicatorInstance.gameObject); } }
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); } } } } } }
protected virtual void FixedUpdate() { if (Target != null) { // Get the main camera var mainCamera = Camera.main; // Begin dragging if (Input.GetKey(Requires) == true) { var position = D2dHelper.ScreenToWorldPosition(Input.mousePosition, Intercept, mainCamera); var factor = D2dHelper.DampenFactor(Dampening, Time.fixedDeltaTime); Target.velocity += (Vector2)(position - Target.transform.position) * factor; } } }
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); } } }
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 at that point D2dStamp.All(Paint, position, Size, Angle, Shape, Color, Layers); } // Update indicator? if (down == true && IndicatorPrefab != null) { if (indicatorInstance == null) { indicatorInstance = Instantiate(IndicatorPrefab); } indicatorInstance.transform.position = position; } // Destroy indicator? else if (indicatorInstance != null) { Destroy(indicatorInstance.gameObject); } } }
protected virtual void Update() { // Get the main camera var mainCamera = Camera.main; // Begin dragging if (Input.GetKey(Requires) == true && down == false) { down = true; startMousePosition = Input.mousePosition; } // End dragging if (Input.GetKey(Requires) == false && down == true) { down = false; // Throw prefab? if (mainCamera != null && ProjectilePrefab != null) { var projectile = Instantiate(ProjectilePrefab); var startPos = D2dHelper.ScreenToWorldPosition(startMousePosition, Intercept, mainCamera); var currentPos = D2dHelper.ScreenToWorldPosition(Input.mousePosition, Intercept, mainCamera); var angle = D2dHelper.Atan2(currentPos - startPos) * Mathf.Rad2Deg; var rigidbody2D = projectile.GetComponent <Rigidbody2D>(); if (rigidbody2D != null) { rigidbody2D.velocity = (currentPos - startPos) * ProjectileSpeed; } angle += Random.Range(-ProjectileSpread, ProjectileSpread); projectile.transform.position = startPos; projectile.transform.rotation = Quaternion.Euler(0.0f, 0.0f, -angle); } } // Update indicator? if (down == true && mainCamera != null && IndicatorPrefab != null) { if (indicatorInstance == null) { indicatorInstance = Instantiate(IndicatorPrefab); } var startPos = D2dHelper.ScreenToWorldPosition(startMousePosition, Intercept, mainCamera); var currentPos = D2dHelper.ScreenToWorldPosition(Input.mousePosition, Intercept, mainCamera); var scale = Vector3.Distance(currentPos, startPos) * Scale; var angle = D2dHelper.Atan2(currentPos - startPos) * Mathf.Rad2Deg; // Transform the indicator so it lines up with the slice indicatorInstance.transform.position = startPos; indicatorInstance.transform.rotation = Quaternion.Euler(0.0f, 0.0f, -angle); indicatorInstance.transform.localScale = new Vector3(scale, scale, scale); } // Destroy indicator? else if (indicatorInstance != null) { Destroy(indicatorInstance.gameObject); } }