public void SpawnJuice(int step, JellyTypes type, bool hasPower) { Juice juice = Instantiate(juicePrefab[(int)type]) as Juice; juice.transform.position = controller.transform.position - new Vector3(0, 1, 0); if (hasPower) { GameObject glow = Instantiate(glowingJuice) as GameObject; glow.transform.parent = juice.transform; glow.transform.localPosition = Vector3.zero; } int topRow = FindSpawnJellyPositionY(step); float topRowPosY = 0; if (topRow != -1) { Jelly topJellp = jellyArray[topRow].Column[step]; topRowPosY = topJellp.transform.position.y; } juice.ActivateMovement(topRowPosY, hasPower); jellyArray[topRow + 1].Column[step] = juice.AddJelly((int)type, step, topRow + 1, hasPower); }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.A)) { if (currentStep > 0) { currentPosition = new Vector3(currentPosition.x - stepX, currentPosition.y, 0); myTransform.position = currentPosition; currentStep--; } } if (Input.GetKeyDown(KeyCode.D)) { if (currentStep < maxStep) { currentPosition = new Vector3(currentPosition.x + stepX, currentPosition.y, 0); myTransform.position = currentPosition; currentStep++; } } if (Input.GetKeyDown(KeyCode.W)) { currentJuice = ((int)currentJuice < (jellyTypes_lvl.Count - 1)) ? currentJuice + 1 : 0; if (currentJuice == 0) { juiceSelction.localPosition -= new Vector3(0, (jellyTypes_lvl.Count - 1) * 30, 0); } else { juiceSelction.localPosition += new Vector3(0, 30, 0); } } if (Input.GetKeyDown(KeyCode.S)) { currentJuice = ((int)currentJuice > 0) ? (JellyTypes)(currentJuice - 1) : (JellyTypes)(jellyTypes_lvl.Count - 1); if ((int)currentJuice == (jellyTypes_lvl.Count - 1)) { juiceSelction.localPosition += new Vector3(0, (jellyTypes_lvl.Count - 1) * 30, 0); } else { juiceSelction.localPosition -= new Vector3(0, 30, 0); } } if (Input.GetKeyDown(KeyCode.R)) { if (!isPowering) { EnablePowering(true); } else { EnablePowering(false); } } if (Input.GetKeyDown(KeyCode.Space)) { if (jellyJuiceQuota[(int)currentJuice] <= 0 || spawnerCD != 0) { return; } spawnerCD = 1; JellyTypes juice = currentJuice; GameManager.GetInstance.SpawnJuice(currentStep, juice, isPowering); jellyJuiceQuota[(int)juice]--; juiceQuotaText[(int)juice].text = jellyJuiceQuota[(int)juice].ToString(); if (isPowering) { powerQuota--; if (powerQuota == 0) { EnablePowering(false); } } else { AddPower(power_basicAdd); } } if (spawnerCD > 0) { spawnerCD -= Time.deltaTime; } else { spawnerCD = 0; } powerQuotaText.text = powerQuota.ToString(); }