Question by
cadeautje · Oct 09, 2015 at 01:23 PM ·
c#prefablocalscale
localscale not working
I am trying to scale a prefab after its instantiated but the scale just doesn't get changed and I don't get any errors either.
here is my code:
IEnumerator spawnBird1()
{
wait = Random.Range (5f, 10f);
yield return new WaitForSeconds (wait);
Debug.Log ("spawn1");
Vector3 spawnPosition = new Vector3 (-50f, Random.Range (8f, 25f) ,8f);
Instantiate (Bird, spawnPosition , Quaternion.identity);
Vector3 scale = Bird.transform.localScale;
scale.x = 2f;
scale.y = 2f;
index = Random.Range (1,4);
switch (index)
{
case 1:
StartCoroutine ( spawnBird1() );
break;
case 2:
StartCoroutine ( spawnBird2() );
break;
case 3:
StartCoroutine ( spawnBird3() );
break;
}
}
Comment
Best Answer
Answer by Denvery · Oct 09, 2015 at 01:49 PM
Please write
Bird.transform.localScale = new Vector3(2f, 2f, Bird.transform.localScale.z)
The line
scale = Bird.transform.localScale;
copies value Bird.transform.localScale to new variable scale. So if we change scale's x & y, it will not affect to Bird.transform.localScale
Your answer
![](https://koobas.hobune.stream/wayback/20220612040644im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how to check the value of localScale.x? [2D] 0 Answers
FPS , Getting invalid AABB(I used animated machine gun that is available in unity asset) 0 Answers
Variable Becoming null only inside functions 2 Answers
Find instantiated prefab by name 3 Answers
how to scale an object on instantiate with a random value 1 Answer