- Home /
Question by
hotozi · Aug 13, 2012 at 04:37 AM ·
collisiongameobjectvariable
Change gameObject of the VAR TARGET HELP!!!
supose that my character collide with an certain objec that tag="Grab"...i want that object to be the var Target when i hit it...HOW the F. can i do this....i tried this...but no way!!
var Target:GameObject;
function OnCollisionEnter(Hitting:Collision){
if(Hitting.gameObject.tag=="Grab"){gameObject.Hitting=Target;}}
Comment
Best Answer
Answer by AutoFredrik · Aug 13, 2012 at 04:12 PM
Almost correct. Try this instead:
var target : transform;
function OnCollisionEnter(collision : Collision)
{
if(collision.gameObject.CompareTag("Grab"))
{
target = collision.gameObject.transform
}
}
Basicly the same thing, just slightly different. Please tell me if it doesn't work.
This is more correct but also just almost correct.
The type is called "Transform" with a capital "T".
Second thing is you missed a semicolon(;) at the end of your assignment