- Home /
Question by
Darklink999999 · Oct 19, 2019 at 10:09 PM ·
gameobjectinstantiatecomponent
Cannoot change variable of Component after Instantiating GameObject
Hello I'm trying to change some variables of a Component of a GameObject after Instantiating, this is the code:
projectile = GameObject.Instantiate (Resources.Load<GameObject>("Fighting/EnemyProjectile"), this.transform.position + this.transform.forward * 2f + this.transform.up, Quaternion.identity) as GameObject;
projectile.GetComponent <Projectile> ().parentPlayerFight = this;
projectile.GetComponent <Projectile> ().target = this.enemy;
For some reason the variables' values in the Component don't change. What am i doing wrong?
Comment
I don't see why this code would not work. What makes you say the variables are not changed? Have you tried a simple Debug.Log(projectile.GetComponent <Projectile> ().parentPlayerFight, projectile)
? Have you tried to call Debug.Break()
to pause the game and see the values of the component?