- Home /
Instantiating and setting localScale doesn't work
Hello! In this script in my game, when my player triggers a collision it will set off a trap that throws one knife/kunai at the player with a chance to throw a second in another direction. I am instantiating the second kunai and changing its scale using the code below, and the debug.log confirms that the local scale is 1, -1, 1. But the object according to the inspector stays at 1, 1, 1, which isn't what I need.
public GameObject laserKunai;
void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Throw"))
{
Instantiate(laserKunai, gameObject.transform.position, Quaternion.identity);
if (Random.value > 0.5)
{
GameObject secondLaserKunai = Instantiate(laserKunai, gameObject.transform.position, Quaternion.identity) as GameObject;
secondLaserKunai.transform.localScale = new Vector3(1, -1, 1);
Debug.Log(secondLaserKunai.transform.localScale);
}
}
}
The laserKunai object has a child object attached to it which holds the sprite renderer and the animator, so I don't think it is an animation related issue, but I'm stumped on this one so any help would be amazing!
Answer by Nistroy · Feb 16, 2021 at 05:27 PM
When you look in the hierarchy, are you looking at the clone or at the uninstantiated object? @chrisd313