private void CheckToClickCandy() { if (InputManager.TouchStart() && !this.isClicked) { Ray ray = InputManager.GetTouchPointRay(); RaycastHit2D rayHit = Physics2D.Raycast(ray.origin, ray.direction, 15.0f, 1 << LayerMask.NameToLayer("Candy")); if (rayHit) { CandyController candy = rayHit.transform.gameObject.GetComponent <CandyController>(); this.selectedCandyType = candy.Type; AddSelectedCandy(candy); this.comboFont.OnLink(1, candy.transform.position); Sound.SoundManager.Instance.PlayEffectSound(Sound.EEffectSoundType.LinkCandy); } this.isClicked = true; } else if (InputManager.Touching() && this.isClicked) { if (this.selectedCandy.Count == 0) { return; } Ray ray = InputManager.GetTouchPointRay(); RaycastHit2D rayHit = Physics2D.Raycast(ray.origin, ray.direction, 15.0f, 1 << LayerMask.NameToLayer("Candy")); if (rayHit) { if (this.selectedCandy.Last().gameObject != rayHit.transform.gameObject) { if (this.selectedCandy.Count > 1 && this.selectedCandy.SecondLast().gameObject == rayHit.transform.gameObject) { RemoveLastSelectedCandy(); this.comboFont.OnLink(this.selectedCandy.Count, this.selectedCandy.Last().transform.position); Sound.SoundManager.Instance.PlayEffectSound(Sound.EEffectSoundType.DelinkCandy); } else { CandyController candy = rayHit.transform.gameObject.GetComponent <CandyController>(); if (!candy.Selected && candy.Type == this.selectedCandyType && MAX_RANGE_FOR_SELECT > Vector2.Distance(this.selectedCandy.Last().transform.position, candy.transform.position)) { AddSelectedCandy(candy); this.comboFont.OnLink(this.selectedCandy.Count, candy.transform.position); Sound.SoundManager.Instance.PlayEffectSound(Sound.EEffectSoundType.LinkCandy); } } } } } else if (InputManager.TouchEnd()) { this.isClicked = false; PangCandies(); } }
private void CreateCandies(int _candyNum) { GameObject candyPrefab = Test.Util.PrefabFactory.Instance.FindPrefab("Candy"); if (candyPrefab == null) { candyPrefab = Test.Util.PrefabFactory.Instance.CreatePrefab("InGame", "Candy", true); } Vector2 candyScale = candyPrefab.transform.lossyScale; float startPos_X = GetCandyStartPosX(_candyNum, candyScale.x); for (int i = 0; i < _candyNum; ++i) { CandyController candy = Instantiate(candyPrefab, this.transform).GetComponent <CandyController>(); candy.transform.localPosition = new Vector2( startPos_X + (i % X_NUM_FOR_CREATE) * (candyScale.x + SPACE_FOR_CREATE) , START_POS_Y_FOR_CREATE + (i / X_NUM_FOR_CREATE) * (candyScale.y + SPACE_FOR_CREATE)); candy.SetType((ECandyType)Random.Range(0, (int)ECandyType.End - 1)); candy.gameObject.SetActive(false); this.candyList.Add(candy); } }
private void AddSelectedCandy(CandyController _candy) { this.lineForCandy.AddPoint(_candy.gameObject); _candy.SelectMe(); this.selectedCandy.Add(_candy.GetComponent <CandyController>()); }