- Home /
Prefab color is black
Hello , I am making a simple game in which the player have to dodge from the falling obstacles . Its all working fine but with just adding two lines of code the prefab color become black .
if (Time.time > nextSpawnTime) {
nextSpawnTime = Time.time + spawnDuration;
// Generating randon X Pos and specific Y Pos
float randomSpawnPosition = Random.Range (-halfScreenSizeUnits, halfScreenSizeUnits);
float initiatePoint = Camera.main.orthographicSize + 2;
// Generating position for Blocks
Vector2 spawnPosition = new Vector2 (randomSpawnPosition, initiatePoint);
float randomSpawnAngle = Random.Range (-spawnAngle, spawnAngle);
GameObject newBlock = (GameObject)Instantiate (enemyPrefab, spawnPosition, Quaternion.Euler(Vector3.forward * randomSpawnAngle));
float spawnSize = Random.Range (spawnSizeMinMax.x, spawnSizeMinMax.y);
newBlock.transform.localScale = Vector2.one * spawnSize;
}
So here everything is fine . The problem is in the last two lines . If I comment these 2 lines then the prefab instantiate randomly and with its own color but if I remove the comment the prefabs becomes black . what's the problem with that ?
Answer by SandScorp · Dec 31, 2017 at 09:05 AM
Hi,
Edited my answer after reviewing I noticed you are using a vector2.
Using a Vector2 this will set the Z value of localScale to 0 automatically because localScale is a vector3. If one of the values of localScale is 0, it would prevent the lighting from affecting it alltogether. Using a vector3 instead of a vector2 would be enough to fix your issue.
So it would end up looking like this:
newBlock.transform.localScale = Vector3.one * spawnSize;