Question by
Kemorno · Apr 11, 2017 at 06:19 PM ·
scripting problemreferencing
How Do I Refer the origin point in C#?
i want to refer the origin point of a cloned prefab, so i can compare the distance between the actual point, and the origin point, so if it is more than the range, it will be destroyed...
do i need to create a null gameObject?
i'm thinkng of something like
{
range=500
deltaDistance=(origin.x-actual.x)+(origin.z-actual.z)+(origin.y-actual.y)
if (DeltaDistance >= range)
destroy(*ThisObject*)
}
Comment
What do you mean by origin point? 0,0,0? It's parent? Btw. Vector3.Distance() is nice and short
maybe i did not explain it as i should, the thisobject is a clone created trough instatiation, so i want the origin point, where the clone was created...
Best Answer
Answer by mbzdmvp · Apr 11, 2017 at 09:29 PM
You'll have to store the original position as a global variable using the Vector3 type.
Something like this in your Start function should work:
Vector3 origin;
void Start() {
origin = transform.position;
}