public void Spawn(int randTurret) { RandTurret = randTurret; isSpawning = true; if (isSpawning == true) { // Debug.Log ("Should have spawned"); isSpawning = false; // RandTurret = Random.Range (0, 1); Vector3 position = Vector3.zero; if (directionFrom == 90) { TurretWidth = (Turret[RandTurret].GetComponent <SpriteRenderer> ().sprite.bounds.max.x) * 2; position.Set(Random.Range(RoomMinX + TurretWidth, RoomMaxX - TurretWidth), transform.position.y, 0.0f); // return; } else if (directionFrom == 270) { TurretWidth = (Turret[RandTurret].GetComponent <SpriteRenderer> ().sprite.bounds.max.x) * 2; position.Set(Random.Range(RoomMinX + TurretWidth, RoomMaxX - TurretWidth), transform.position.y, 0.0f); // return; } else if (directionFrom == 180) { TurretHeight = (Turret[RandTurret].GetComponent <SpriteRenderer> ().sprite.bounds.max.y) * 2; position.Set(transform.position.x, Random.Range(RoomMinY + TurretHeight, RoomMaxY - TurretHeight), 0.0f); // return; } else if (directionFrom == 0) { TurretHeight = (Turret[RandTurret].GetComponent <SpriteRenderer> ().sprite.bounds.max.y) * 2; position.Set(transform.position.x, Random.Range(RoomMinY + TurretHeight, RoomMaxY - TurretHeight), 0.0f); } Quaternion rotation = Quaternion.identity; GameObject turretGameObject = (GameObject)Instantiate(Turret[RandTurret], position, rotation); TurretScript tScript = turretGameObject.GetComponent <TurretScript> (); //Debug.Log ("tScript"); tScript.setTurretType(RandTurret); tScript.setAnim(true, directionFrom); } }