- Home /
What data is stored in "other"?
in OnTriggerEnter (OTHER : Collider); what data is stored in the other? because for the past little bit i have been using as if it was a gameobject, but it isnt working out. so i would like to know what exactly it is reffering to there?
Assets/LookAt.js(9,33): BCE0023: No appropriate version of 'UnityEngine.Transform.LookAt' for the argument list '(UnityEngine.GameObject)' was found.
now its giving me this... which is kinda contridicting its self...
i am so thankful for you help though! i have posted and reposted questions like this for about 3 weeks now and no one could help me... like no one even told me that collider could be extended. so thank you
Yeah, I missed that: LookAt can accept a Transform, not a GameObject - just add .transform to the monster variable:
...
if (attackRTriggerStay.targetAquired){
transform.LookAt(attackRTriggerStay.monster.transform);
}
...
I fixed this in the answer too.
!!!!!!!!!!!!!!!!!! you saved me!!! ha ha i am so happy right now!!! i knew while i was working on it it would be something simple that i was overlooking, but i didnt even know that a collider could take that stuff after its been assigned! thank you again
Answer by aldonaletto · Aug 16, 2011 at 04:17 AM
A Collider has direct access to the same inherited variables as a Transform or GameObject, like transform, gameObject, rigidbody, collider, name, tag etc. (take a look at the Inherited Variables in Collider to get a complete list).
EDITED: A game object has some basic variables (transform, collider, rigidbody, gameObject) that can be used as references to other variables of the same object. If you have transform, but want to get the gameObject reference, you can use transform.gameObject;
var invaderGameObject: GameObject; var invaderTransform: Transform;
function OnTriggerEnter(other:Collider){ invaderGameObject = other.gameObject; invaderTransform = other.transform; } EDITED2: The trigger script may declare targetAquired and monster as static variables, and read them in the tower script.
This is the trigger script:
static var targetAquired = false; static var monster: GameObject;
function OnTriggerEnter (other : Collider) { if(other.gameObject.CompareTag ("enemy")){ monster = other.collider.gameObject; targetAquired = true; } }
function OnTriggerExit (other : Collider) { if(other.gameObject.CompareTag ("enemy")){ targetAquired = false; } }
The tower script (below) must read the static variables using the name of the trigger script (what I suppose is attackRTriggerStay.js):
function Update () {
if (attackRTriggerStay.targetAquired){
transform.LookAt(attackRTriggerStay.monster.transform);
}
}
so how would i go about accessing that colliders transform? so that i could then use it in the transform.LookAt()?
Who do you want to look at who? other look at some object, or the trigger owner to look at owner?
want another object that gets info from the trigger owner to look at the trigger causer.... so basically a tower looking at an enemy with an attack radius.
but from what i understand looking at this object is next to impossible because it is a collision class. therefore cannot be used as a transform class which makes absolutely no sense to me...
It's simple: the collider is one of the basic object variables, and these basic variables can access each other directly - if you have the object's collider, you can get its transform as collider.transform, or its gameObject as collider.gameObject. Take a look at my edited answer.
Your answer