Change game-cursor on gameobjects within range
Hi. I have a problem with the following code: using UnityEngine; using System.Collections; using UnityEngine.EventSystems; public class Move : MonoBehaviour { public bool Cursor_enemy = false; public...
View Articleif loop running when it shouldn't
In my videogame the player has to copy a text using the keyboard and the game, after checking the spelling of all the characters of all the words, updates the text to be copied in real time. So I...
View ArticleBreaking out of problem code
is there a way to set a kind of timer at the start of every frame that will cause an event if the time between frames is too high, like 10 secs for example, if you're getting an fps of 0.1 then theres...
View ArticleUnity keeps crashing due to unknown infinite loop?
Yo So I am very nooby with C#. I am currently following a tutorial to make a memory game (https://www.youtube.com/watch?v=prfzIpNhQMM). I have followed it all and managed to fix all problems I ran into...
View ArticleHow to destroy numbers after solving them?
I'm making a calculator game for my final project in a beginning scripting class. The premise of it is that randomly generated numbers are falling from the top of the scene, and when they hit a...
View ArticleUsing a coroutine to increment a for loop?
So I'm making a strategy game where the player will take their turn, then each enemy unit will go one by one, then the player's turn will start again. Right now what happens is it will cause all units...
View ArticleNested loop queston
I'm trying to create a 5 x 5 grid of spheres using a nested loop. it looks like this: public GameObject ball: for (int y = 0; y < 5; y++){ for ( int x = 0; x < 5; x++){ GameObject spheres =...
View ArticleWhy is this IEnumerator instantly crashing my game?
IEnumerator Dungeon() { int X = Random.Range (-3, 3)*2; int Y = Random.Range (-2, 2)*2; Vector2 pos = new Vector2 (X, Y); if (Vlist.Contains (pos) == true) { print ("repeated"); yield return Dungeon...
View ArticleCant loop through a List
Here is the code in question: public List craftingItems = new List(); public void checkIfItemIsCraftable(){ for (int i = 0; i < inv.database.craftingDatabase.Count; i++) { for (int x = 0; i <...
View ArticleC# Yield WaitForSeconds within For Loop
I am trying to use two yields within a coroutine loop (because I need to iterate out arrays with pauses between each loop). The first loop works correctly, with all the yields working for the right...
View ArticleTurn off script in multiple objects
So I am at loss. I am trying to find and disable script on each enemy object in game. I have foreach loop at awake that finds gameobjects with tag "Enemy", and finds script attached to it...
View ArticleWhile Loop Freezing Unity
What's wrong with this code? Whenever OnMouseDown is called unity freezes. public class createTroops : MonoBehaviour { public stats statsVars; public GameObject prefab; public int incPos = 4; void...
View ArticleComparing distance of vector 3's on a dynamic growing list
I have a script that is spawning treasure in random locations. I want the script to detect if a treasure has been placed, then save that placed position in a list. Once i spawn the next treasure, I...
View ArticleYield return statement ends loop execution
I've been working on a coroutine that splits text into a list of words, taking a break at every 500-ish characters parsed. See here: // charsToParsePerFrame = 500 // other code while...
View ArticleFor Loop looping out of Loop Condition
Hey guys, So this bit of error is confusing the heck out of me. For whatever reason, the for loop is not exiting after the loop condition is met: ![alt text][1] Notice the last 3 lines in the console,...
View ArticleAdd existing variables to an array?
I have a few float variables and an array `public float zero = 10.5;` `public float one = 25;` `public float two = 50;` `public float three = 75;` `public float four = 12.5;` `public float five = -65;`...
View ArticleInstantiating game objects in spiral pattern
I am trying to create grid tiles for a system in my game and without the proper algorithm right now it just starts spawning them from the bottom left side. for (int x = 0; x < width; x++) { for (int...
View ArticlePath Generation in procedural terrain generation
Salam, Hi, I am keen to know if there is a way to generate paths while using procedural terrain generation. For example if I want to generate a map/terrain randomly with some certain number of paths...
View ArticleHOW to USE LOOPS withinh Update???
HI Guys!!! i have fought with this!!! hehehe void Update(){ While(condition){ //actions } } Why would i do something like this? simple!! some situations could need it!! for example, if i try to develop...
View Articlehow to tell if a for loop has completed
I've been having trouble with for loops. I've created a simple for loop that decides how far my units move for (int i = 0; i < moveSpeed; i++) { //moves unit if (i == moveSpeed) { path = null; } }...
View Article