public void SpawnCockblocker() { int angleRand = rand.Next(0, (int)(360 / angle)); GameObject parent = new GameObject(); parent.transform.SetParent(smallGemParent, false); GameObject GO = Instantiate(cockBlockerPrefab); GO.transform.SetParent(parent.transform, false); GO.transform.localPosition = new Vector3(0, minDistance + blockHeight * (maxRows * 2.4f)); //GO.transform.localPosition = new Vector3(Mathf.Cos((angleRand * angle) * Mathf.Deg2Rad), Mathf.Sin((angleRand * angle) * Mathf.Deg2Rad)) * (minDistance + blockHeight * (maxRows - 1)); parent.transform.rotation = Quaternion.AngleAxis(angleRand * angle - 90, new Vector3(0, 0, 1)); tk2dSlicedSprite sp = GO.GetComponent<tk2dSlicedSprite>(); Vector2 v = sp.dimensions; v.x = maxGemWidth; sp.dimensions = v; SpawnGem s = new SpawnGem(); s.sprite = sp; s.prefab = GO; s.col = GO.GetComponent<BoxCollider2D>(); s.type = GemType.Cockblocker; s.targetAngle = angleRand * angle - 90; var i = ((angleRand + (int)((360 - transform.eulerAngles.z) / angle)) + 1) % (int)(360 / angle); spawnedGems.Add(s); }
public void CheckCombo(SpawnGem gem) { if (gem.type != GemType.Cockblocker) { gem.col.enabled = true; RaycastHit2D[] hits = new RaycastHit2D[5]; List<SpawnGem> gems = new List<SpawnGem>(); gems.Add(gem); Vector2[] directions = new Vector2[] { gem.prefab.transform.up, -gem.prefab.transform.up, gem.prefab.transform.right, -gem.prefab.transform.right }; float width = Mathf.Lerp(1.3f, 3, (Vector3.Distance(transform.position, gem.prefab.transform.position) - minDistance) / ((minDistance + blockHeight * (maxRows - 1)) - minDistance)); float[] distances = new float[] { .45f, .45f, width, width }; for (int i = 0; i < directions.Length; i++) { int count = Physics2D.RaycastNonAlloc(gem.prefab.transform.position, directions[i], hits, distances[i]); //if (i == 2 || i == 3) //{ // Debug.DrawRay(gem.prefab.transform.position, directions[i] * distances[i]); //} for (int x = 0; x < count; x++) { if (hits[x].collider.gameObject != gem.prefab) { if (hits[x].collider.gameObject.tag == gem.prefab.gameObject.tag) { SpawnGem foundGem = spawnedGems.First(s => s.prefab == hits[x].collider.gameObject); if (!foundGem.moving && !gem.moving) { if (!gems.Contains(foundGem)) { gems.Add(foundGem); } } } } } } gem.col.enabled = true; if (gems.Count >= 3) { for (int i = 0; i < gems.Count; i++) { spawnedGems.Remove(gems[i]); Destroy(gems[i].prefab.transform.parent.gameObject); } SpawnMinion(gems[0].type); pling.pitch = UnityEngine.Random.Range(0.9f, 1.1f); pling.PlayOneShot(plingClip); } } }