how to instantiate a prefabs that move upward on update function and get the transform position of that moving prefab
I have four game object that moves upward on update function. Normally, I am able to get the transform position of that four moving game object. But when I make prefab of that four game object and instantiate it, then I am failed to get the transform position of that four moving prefab.
class for moving object.. this class is attached to four game object
void Update()
{
Vector3 position = this.transform.position;
position.y=position.y+(Time.deltaTime*mySpeed);
this.transform.position = position;
}
class for instantiating prefab
void Start()
{
Instantiate (indi1);
Instantiate (indi2);
Instantiate (indi3);
Instantiate (indi4);
}
class for getting the game object of the prefab..
[SerializeField]
Transform indicator1;
[SerializeField]
Transform indicator2;
[SerializeField]
Transform indicator3;
[SerializeField]
Transform indicator4;
void Update()
{
vector3 pos1=indicator1.transform.position;
Debug.Log(" Position is "+pos1);
}
//unable to get position of the prefab from above class
error : MissingReferenceException: The variable indicator1 of moveCar1F doesn't exist anymore.
Your answer
Follow this Question
Related Questions
How to stop movement script on void start and resume after. 0 Answers
How do I enable/disable components in a prefab from another script? 1 Answer
Giving different values to cloned prefabs with the same script. 1 Answer
My movement script is not moving my 2D object 2 Answers
Special movement for game 1 Answer