- Home /
convert a collider array to a list transform
hi there.
my problem is: i want to use overlapsphere to find some objects in range but overlapsphere gives me only a collider array as output...
what is the best way to convert this array to a list?
c# and universe. universe making it a bit harder to code things... becouse i need to keep the programm flow.
i´m brutforcing this code since 8hours... and i don´t get it..
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Antares.Vizio.Runtime;
[VisualLogicBlock("overlap with list out", "Realy Smart Blocks")]
public class overlapsphere_with_list_out : LogicBlock
{
[Parameter(VariableType.In, typeof(Vector3))]
public Variable zeropoint;
[Parameter(VariableType.In, typeof(float))]
public Variable radiusss;
[Parameter(VariableType.In, typeof(Layer$$anonymous$$ask))]
public Variable lay;
[Parameter(VariableType.Out, typeof(List<Collider>))]
public Variable result2;
public override void OnInitializeDefaultData()
{
RegisterOutputTrigger("Exit");
}
[EntryTrigger]
public void In()
{
List<Collider> result2 = new List<Collider> (Physics.OverlapSphere(zeropoint,radiusss,lay));
return result2;
ActivateTrigger("Exit");
}
}
this is log after saving...
her is a link for the realsize version. http://image-upload.de/image/39fDAm/4db636d343.jpg
Answer by gregzo · Sep 05, 2012 at 02:57 PM
I'm not sure if this is what you need, plus I'll give you UnityScript, but here's the idea:
Colliders and transforms are components attached to gameObjects. So to get the transform from a collider, you can do collider.gameObject.GetComponent(Transform);
Code:
function CollidersToTransforms(cols:Collider[])
{
var transformsList = new List.<Transform>(cols.length);
for(col in cols)
{
transformsList.Add(col.gameObject.GetComponent(Transform);
}
return transformsList;
}
I hope it helps!