static void OnPowerupCollect(Powerup powerup) { var colorizer = powerup.GetComponent <Colorizer>(); if (colorizer != null) { PowerupColorDisplay.AddColor(colorizer.Color); } }
IEnumerator Start() { gameStatus = FindObjectOfType <GameStatus>(); while (true) { yield return(new WaitForSeconds(Random.Range(minSpawnTime, maxSpawnTime))); float xPos = transform.position.x + Random.Range(1f, maxPlayAreaWidth - 1f); float yPos = transform.position.y; Vector2 spawnPos = new Vector2(xPos, yPos); Powerup newPowerup = Instantiate(powerups[Random.Range(0, powerups.Length)], spawnPos, Quaternion.identity); newPowerup.GetComponent <Rigidbody2D>().velocity = new Vector2(0, -(powerupVelocity + (gameStatus.GetScore() / difficultyFactor))); newPowerup.transform.parent = transform; } }
private void OnCollisionEnter(Collision collision) { if (collision.gameObject.tag == "Player") { Powerup randomItem = Powerups[Random.Range(0, Powerups.Length)].GetComponent <Powerup>(); Debug.Log(randomItem.GetComponent <Powerup>()); //if (!GameObject.Find("PowerUpManager").GetComponent<powerUpManager>().CR_running) if (collision.gameObject.GetComponentInParent <powerupSlot>().current == null) { collision.gameObject.GetComponentInParent <powerupSlot>().updateCurrentItem(randomItem); GameObject.Find("Power Up SpawnPoints").GetComponent <PowerBoxSpawn>().currentCubes--; Destroy(gameObject); } else { GameObject.Find("Power Up SpawnPoints").GetComponent <PowerBoxSpawn>().currentCubes--; Destroy(gameObject); } } }
//random spawn of cubes and powerups private void SpawnCubesAndPowerups() { mNextSpawn -= Time.deltaTime; mNextPowerupSpawn -= Time.deltaTime; if (mNextSpawn <= 0.0f && GetAllCubes().Length < MAX_CUBES) { if (mObjects == null) { mObjects = new List <GameObject>(); } GameObject spawnObject = SpawnPrefabs[1]; GameObject spawnedInstance = Instantiate(spawnObject); spawnedInstance.transform.parent = transform; SetRandomPos(spawnedInstance); mObjects.Add(spawnedInstance); mNextSpawn = TimeBetweenSpawns; NetworkServer.Spawn(spawnedInstance); } if (mNextPowerupSpawn <= 0.0f && GetComponentsInChildren <Powerup>().Length < MAX_POWERUPS) { GameObject powerupSpawn = PowerupPrefab; Powerup powerupInstance = (Powerup)Instantiate(powerupSpawn).GetComponent <Powerup>(); powerupInstance.transform.parent = transform; powerupInstance.GetComponent <Powerup>().SetRandomType(); SetRandomPos(powerupInstance.gameObject); mNextPowerupSpawn = TimeBetweenPowerupSpawns; NetworkServer.Spawn(powerupInstance.gameObject); powerupInstance.RpcUpdateRenderTypes(); //mObjects.Add(powerupInstance); } }
public void ChangePowerup(Powerup newPowerup) { currentPowerup = newPowerup; powerupImage.sprite = newPowerup.GetComponent <SpriteRenderer>().sprite; }