void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.tag.Equals("Candy")) { Candy candy = (Candy)col.gameObject.GetComponent <Candy>(); int points = candy.GetCandyPoint(); myPlayerInfo.localCharacterScore += points; myPlayerInfo.globalCharacterScore += points; //int local = myPlayerInfo.localCharacterScore; //int global = myPlayerInfo.globalCharacterScore; //myPlayerInfo.IncrementScore(local, global); //Network.Destroy(col.gameObject.GetComponent<NetworkIdentity>().netId); if (isServer) { NetworkServer.Destroy(candy.gameObject); } else { CmdDestroyCandy(candy.GetComponent <NetworkIdentity>().assetId); } if (floatingText) { ShowFloatingText(points); } } }
private Candy InstatiateCandyAtPosition(Candy prefabToInstatiate, Vector2 position) { Candy candy = Instantiate(prefabToInstatiate, m_startSpawnPosition, prefabToInstatiate.transform.rotation) as Candy; candy.gameObject.transform.SetParent(gameObject.transform, false); candy.GetComponent <RectTransform>().anchoredPosition = position; return(candy); }
public void SwapSprite(Candy newCandy) { if (spriteRenderer.sprite == newCandy.GetComponent <SpriteRenderer>().sprite) { return; } Sprite oldCandy = newCandy.spriteRenderer.sprite; newCandy.spriteRenderer.sprite = this.spriteRenderer.sprite; this.spriteRenderer.sprite = oldCandy; int tempId = newCandy.id; newCandy.id = this.id; this.id = tempId; }
public void SwapSprite(Candy newCandy) { if (spriteRenderer.sprite == newCandy.GetComponent <SpriteRenderer>().sprite) { return; } //para hacer un swap, nesesitamos un auxiliar. Sprite oldCandy = newCandy.spriteRenderer.sprite; newCandy.spriteRenderer.sprite = this.spriteRenderer.sprite; this.spriteRenderer.sprite = oldCandy; int auxId = newCandy.id; newCandy.id = this.id; this.id = auxId; }
public void SwampSprite(Candy newCandy) { // Si es el mismo SPRITE => return; if (spriteRenderer.sprite == newCandy.GetComponent <SpriteRenderer>().sprite) { return; } // Intercambio SPRITE Sprite oldCandy = newCandy.spriteRenderer.sprite; newCandy.spriteRenderer.sprite = this.spriteRenderer.sprite; this.spriteRenderer.sprite = oldCandy; // Intercambio ID int oldId = newCandy.id; newCandy.id = this.id; this.id = oldId; }
public void SwapSprite(Candy firstCandySelected) //Intercambiar candys { if (spriteRenderer.sprite == firstCandySelected.GetComponent <SpriteRenderer>().sprite) //Si el sprite del segundo candy seleccionado(este candy) es igual al del primero seleccionado... { return; //... no hara nada } //Como no hace nada, despues de aqui el codigo no sigue //Intercambio de sprites Sprite tempSprite = firstCandySelected.spriteRenderer.sprite; //Variable auxiliar que almacena el sprite del primer candy seleccionado firstCandySelected.spriteRenderer.sprite = this.spriteRenderer.sprite; //El sprite del primer candy seleccionado sera el de este, o sea, el del segundo candy seleccionado this.spriteRenderer.sprite = tempSprite; //El sprite de este candy(el segundo seleccionado), sera el del primero, guardado en la variable tempSprite //Intercambio de ids int tempId = firstCandySelected.id; //Variable auxiliar que almacena el id del primer candy seleccionado firstCandySelected.id = this.id; //El id del primer candy seleccionado sera el de este, o sea, el del segundo candy seleccionado this.id = tempId; //El id de este candy(el segundo seleccionado), sera el del primero, guardado en la variable tempId }
private Candy crtCandy = null; //标记Candy //协成,选择Candy public IEnumerator SelectCoro(Candy c) { //Remove(c); return; if (crtCandy == null) { crtCandy = c; crtCandy.GetComponent<TweenScale>().enabled = true; yield return null; } else { crtCandy.GetComponent<TweenScale>().enabled = false; crtCandy.transform.localScale = Vector3.one; Debug.Log("fist candy position:" + crtCandy.rowIndex + "," + crtCandy.columnIndex + "...second candy position:" + c.rowIndex + "," + c.columnIndex); if (Mathf.Abs(crtCandy.rowIndex - c.rowIndex) + Mathf.Abs(crtCandy.columnIndex - c.columnIndex) == 1) { Exchange(crtCandy, c); yield return new WaitForSeconds(exchangeSpeed); Debug.Log("!!!check matches:" + CheckMatches()); if (CheckMatches()) { RemoveMatches(); } else { //互相换回来 Exchange(crtCandy, c); yield return new WaitForSeconds(exchangeSpeed); } } crtCandy = null; } StopCoroutine("SelectCoro"); }