• 9
• 9
• 10
• 10
• 9
• ### Similar Content

• ...if you got time to read and answer i would be happy .

So me and my co try to do a game.
It should be in unity couse my co do everything in this engine.

We got the rpg package from evila for inventor, but it only runs on pc right now.

I like to make a online store for guns in the game and a multiplayer open world that runs on pc, android, mobile, ps4, xbox one.
Somebody told me that you "only" need to program it like so and that its possible in every engine...

So if you are one of the lucky guys who could help me out or programm that, or even if you know a newer better package for maybe unreal which offers that - please let me know now.

• I'm having a weird issue with detecting a collision. I've tried everything I could find online but nothing seems to work. I have a brick object. It has a 2D Collider attached and I have also attached a 2D Rigidbody on it. I also have an EndScreen 2D Collider. The EndScreen 2D collider is tagged with "EndScreen". I am trying to detect when a brick collides with the end screen collider and simply print "game over" in the console.
This is my current code for this part of the program, it is attached to the bricks:
void OnCollisionEnter (Collision2D collision) { if (collision.gameObject.tag == "EndScreen") { Debug.Log("Game over"); } } Several things have happened depending on the set up. If I have the rigidbody 2D set as static, my ball object can still collide with the bricks, but I get no Log message. If I set it to Kinematic or Dynamic, I get absolutely no interaction between the ball and the bricks, and nothing when the bricks pass through the collider. I have tried to set the collider to a trigger and use OnTriggerEnter2D, no change. I have tried to put the rigidbody on the EndScreen object and tried to set it's body type to all 3 settings, no change. The only thing I can think of that I have not done is put the script on the EndScreen object and switch the tag to the bricks. The reason I have not done this is because I will have several types of bricks, some of which will have different tags.

Please tell me somebody can see what I'm doing wrong here, because I'm losing my mind over something I feel should be ridiculously simple. Thanks.

# Unity Infinite Loops and State Machines

This topic is 973 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

How do you fix infinite loops

These are the different game states

void Update ()
{
switch (_currentState) {
case GameState.start:
Debug.Log("Start");
_currentState = GameState.inGame;
break;
case GameState.inGame:
//Debug.Log("In Game");
_scoreText.text = "Score: " + _score;
break;
case GameState.gameOver:
Debug.Log("Game Over");			_scoreText.enabled = false;
_gameOverText.enabled = true;
break;		}
}
}


This loops seems to be causing unity to crash

while (GameManager.gameManager.CurrentState == GameManager.GameState.inGame)
{
Debug.Log("Enter Lop");
transform.position = Vector3.Lerp(targetPoint1.position, targetpoint2.position, time);
if (Input.GetKey(KeyCode.Space))
{
GameManager.gameManager.CurrentState = GameManager.GameState.gameOver;
}
}


I have aa means of breaking out of the loop so I'm not sure why unity is crashing

##### Share on other sites

I dont know much about unity, but probably the issue is not that the loop is infinite, but that it never pauses so that input and other things can be processed.

Assuming such an infinite loop is the ideal way to handle constant updating in unity (look at some other peoples code to make sure you got it right) - is there some function in unity to pause the loop so it doesnt hog all the cpu?

this looks like it might work:

http://docs.unity3d.com/ScriptReference/WaitForSeconds.html

(eg call it once in the loop to wait a small time, so the loop runs at a finite rate, like ~30 FPS or whatever you want)

but again, make sure this is the correct way to handle things in unity. Are you sure you cant just put that code in the loop, into the "Update" method? (without the loop)

##### Share on other sites

I've tried using an iEnumerator but the sprite doesn't seem to move bettween the two points.

using UnityEngine;
using System.Collections;

public class EnemyStepController : MonoBehaviour
{
//Points to travel to and from
public Transform[] targetPoints;

public int time = 5;

public IEnumerator StepMovement ()
{
for (int cnt = 0; cnt < targetPoints.Length; cnt++)
{
transform.position = Vector3.Lerp (transform.position,
targetPoints[cnt].position,
time * Time.deltaTime);
}

if (Input.GetKey(KeyCode.Space))
{
GameManager.gameManager.CurrentState = GameManager.GameState.gameOver;
yield break;
}
}

void OnTriggerEnter2D (Collider2D col)
{
if (col.tag == "Player")
{
GameManager.gameManager.CurrentState = GameManager.GameState.gameOver;
}
}
}



Also, whenever I change the time variable in the inspector i get 3 of these errors

Unsupported type vector