- Home /
How do you tranform multiple objects
Just started doing this
public GameObject[] sprite;
public void Slider_Changed (float newValue){
Vector2 pos = sprite.transform.position;
pos.x = newValue;
sprite.transform.position = pos;
}
}
Answer by I_Am_Err00r · Sep 06, 2019 at 04:26 PM
This should do it:
public GameObject[] sprite;
public void Slider_Changed (float newValue)
{
foreach(GameObject obj in sprite)
{
Vector2 pos = obj.transform.position;
pos.x = newValue;
obj.transform.position = pos;
}
}
Assets/Script.cs(9,24): error CS1061: Type UnityEngine.GameObject[]' does not contain a definition for
transform' and no extension method transform' of type
UnityEngine.GameObject[]' could be found. Are you missing an assembly reference? Is I guess what I'm asking
I fixed his code. The original didn't make much sense ^^.
Yep, thanks for that @Bunny83! Was just about to fix when I saw his error. Not the world's most intuitive coder, don't answer these with access to an IDE or $$anonymous$$onoBehaviour.
Your answer
Follow this Question
Related Questions
Need insight on strange (simple) 2D object transform bug 0 Answers
Locating Position of Object not Working? 2 Answers
Best way to detect if an object is near? 1 Answer
postion scale and rotation greyed out and not working 1 Answer
[CODE]Keep Gameobject position exactly at mouse cursor when cast float position to int 1 Answer