- Home /
Rotation Bug
so im pretty new to coding and unity and I was wondering if any of you could help me. I have written this code which works but will also not work at all. (i dont get any error codes either) it will either work or it won't there is no inbetween. I was wondering if any of you could tell me what I need. I'm thinking its a bug because like I said it works... sometimes. what the code is meant to do is chose between different blocks and instantiate blocks with random 90degree rotations. The only thing that i'm having problems with though is the rotation of the blocks. I've added a bad drawing. each square is a block with a shape in the middle and those are the rotations I want. i'ts kind of hard to explain but hopefully someone can help. I've been working on this game for a long time now and I've just about completed it eseides this rotation bug. HELP!!!
using UnityEngine; using System.Collections;
public class WallGenerator : MonoBehaviour {
//public GameObject wall;
public Transform generationPoint;
public float distanceBetween;
private float wallWidth = 1;
int ranNum;
public GameObject[] theWalls;
private int wallSelector;
// Use this for initialization
void Start () {
ranNum = Random.Range (0, 3);
}
// Update is called once per frame
void Update () {
if(transform.position.x < generationPoint.position.x)
{
transform.position = new Vector3 (transform.position.x + wallWidth + distanceBetween, transform.position.y, transform.position.z);
wallSelector = Random.Range (0,5);
Instantiate (theWalls[wallSelector], transform.position, transform.rotation);
transform.Rotate(ranNum*90, 0, 0);
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612075851im_/https://answers.unity.com/themes/thub/images/avi.jpg)