transform of all the childrens in arraylist
in one waypointcontainer there 100 children
arraylist var = waypointcontainer.GetComponentsInChildren(Transform);
i working in c# script and error comes like this expression denotes a ‘type’ where a ‘variable’,'value’or’method group’was expected
but in javascript there no problem if i am using array
plz reply
thanks
arraylist and array are not the same .
try
Transform[ ] var=new Transform[100];
var = (Transform[ ])obj2.GetComponentsInChildren(typeof (Transform));
thanks for the reply it worked but
now i am getting runtime exception
InvalidCastException: Cannot cast from source type to destination type.srr.GetWaypoints () (at Assets\Pro Standard Assets\sss\Scripts\srr.cs:223)
srr.Start () (at Assets\Pro Standard Assets\sss\Scripts\srr.cs:336)
for
potentialWaypoints = (Transform[ ])waypointContainer.GetComponentsInChildren( typeof(Transform ));
NullReferenceException: Object reference not set to an instance of an object
srw.NavigateTowardsWaypoint () (at Assets\Pro Standard Assets\sss\Scripts\srw.cs:82)
srw.Update () (at Assets\Pro Standard Assets\sss\Scripts\srw.cs:18)
for
Vector3 temp=new Vector3( waypoints[currentWaypoint].position.x,transform.position.y,waypoints[currentWaypoint].position.z );
Vector3 RelativeWaypointPosition = transform.InverseTransformPoint(temp);
plz reply
thanks in advance
What does your declaration look like for:
waypointContainer
public GameObject waypointContainer;
in inspector i have assign the gameobject also
That looks okay, as a test what happens when you go?
Component[] potentialWaypoints = waypointContainer.GetComponentsInChildren( typeof(Transform ));
Does it give you back a valid list of components?
You cannot do this:
Transform[] potentialWaypoints = (Transform[])waypointContainer.GetComponentsInChildren( typeof(Transform ));
You have to do this:
Component[] potentialWaypoints = (Transform[])waypointContainer.GetComponentsInChildren( typeof(Transform ));
and then when you access the individual potentialWaypoints elements you cast them then:
for (int i = 0; i < potentialWaypoints.Length; i++)
{
((Transform)potentialWaypoints[i]).yourpropertyhere;
}
that is pseudo-code.
Was an error in second code block I showed above… here is a working example:
Component[] transforms = entity.gameObject.GetComponentsInChildren(typeof(Transform));
for (int i = 0; i < transforms.Length; i++)
{
Transform trans = (Transform)transforms[i];
if (trans.particleEmitter != null)
{
trans.particleEmitter.emit = false;
}
}