Quantcast
Channel: Latest Questions by Caelorum
Viewing all articles
Browse latest Browse all 14

Not all code paths return a value?

$
0
0
I've searched around, but can't seem to figure out why my code paths wouldn't return a value on my IEnumerator RandomColor(). I'm not too familiar with IEnumerator, but after some research it fixed some of my other problems. Javascript was just function. Now I have to use IEnum, class, void. Etc etc etc. A lot to take in. I'm trying to convert all of my JS to C#, and jeez....c# has errors galore. Here is my code: //enemy script using UnityEngine; using System.Collections; public class script_Actor_Enemy_C : MonoBehaviour { //inspector variables int numberOfClicks = 2; //color of the object float respawnWaitTime = 2.0f; //how many times to click on object before destroying int enemyPoint = 1; //value of the enemy object int clipRandom; Color[] shapeColor; //how long to hide object Transform explosion; //load particle effect AudioClip[] clips; private int storeClicks; // Use this for initialization void Start () { storeClicks = numberOfClicks; Vector2 startPosition = new Vector2(Random.Range(-7,7), Random.Range(-4.3f,4.3f)); //new random position for gameobject transform.position = startPosition; RandomColor(); } // Update is called once per frame void Update () { if(numberOfClicks <=0) { if (explosion) { GameObject clone = Instantiate(explosion, transform.position, transform.rotation) as GameObject; //create an explosion Destroy (clone.gameObject,1); } clipRandom = Random.Range(0,3); audio.clip = clips[clipRandom]; audio.Play(); Vector2 position = new Vector2(Random.Range(-7,7), Random.Range(-4.3f,4.3f)); //new random position for gameobject RespawnWaitTime(); transform.position = position; //relocates gameobject to new location numberOfClicks = storeClicks; } } //Respawn Wait Time will be used to hide the gameobject for a certain time, then unhide it IEnumerator RespawnWaitTime() { //makes object invisible renderer.enabled = false; RandomColor(); yield return new WaitForSeconds (respawnWaitTime); renderer.enabled = true; } //Random color is used to change out material of gameobject IEnumerator RandomColor() { if(shapeColor.Length > 0) { int newColor = Random.Range(0,shapeColor.Length); renderer.material.color = shapeColor[newColor]; } } } I'm not seeing what the issue is. When would it not return a value? It should return a value/color change every time. I tried turning the IEnumeration into a void, but that caused even more errors that don't make any sense.

Viewing all articles
Browse latest Browse all 14

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>