- Home /
Trying to draw a rectangle and then draw the same rect using a Gizmo - results are varying
Edit: After some more troubleshooting, it appears the gizmo is drawing at the center of my player, while the rect is being created and only drawing to the right. Going to continue to dig, but any remedies to that?
Currently working to spawn enemies on the outside of a rectangle. I have a prototype that I'm getting close to working and I want to draw the rectangle via gizmo in the scene view for troubleshooting purposes.
Here's what it looks like. I'm expecting the blue dot to be in the upper right of the red gizmo. Any idea why it's not?
Here's the code:
public class EnemySpawner : MonoBehaviour {
public GameObject enemy;
public Vector2 rectspawnSize = new Vector2(4, 4);
void Start() {
Rect spawnRect = new Rect(transform.parent.position, rectspawnSize);
for (int i = 0; i < 10; i++) {
Vector3 enemySpawnPos = new Vector2(spawnRect.xMax, spawnRect.yMax);
Instantiate(enemy, enemySpawnPos, Quaternion.identity);
}
}
private void OnDrawGizmos() {
Gizmos.color = new Color(1, 0, 0, 0.3f);
Gizmos.DrawCube(transform.parent.position, rectspawnSize);
}
}
I'm using the same size for the rectangle creation and the drawing of the Gizmo. What am I missing?
Your answer
Follow this Question
Related Questions
2D Animation does not start 1 Answer
Draw Gizmos for Non-Monobehaviour objects in an Array 0 Answers
Draw 2d circle with Gizmos 6 Answers
How to achieve Dynamic Gizmo DrawLine() 0 Answers