- Home /
Question about tags and variables
Semi new here and don't know what to reference to figure this out.
Question is-- Basically the piece of wall is gameObject C, and when the specific asset touches it, it sticks, but I don't want the whole object touches to make it stick so I made the end a gameObject and tagged it A. How do I make it so if a.gameObject.tag collides with c.gameObject.tag initializes "Stick"?
Example of the "Stick"
var joint = gameObject.AddComponent(FixedJoint); joint.connectedBody = c.rigidbody;
but I don't know how to write that out. How do you code it so that it specifies that "gameObject tag a" has to collide with "gameObject tag c" to initialize "Stick"?
Only reference I've found regards to gameObject A colliding with anything, initializes stick, which I have now, but I want it target specific and I have no clue how to write that out, please help, here is a piece of the code I have which initializes the basic stick.
function OnCollisionEnter(c : Collision) //function OnControllerColliderHit(c : ControllerColliderHit) {
if(c.gameObject.tag == "Stick")
{
transform.eulerAngles = Vector3(90,0,0);
var joint = gameObject.AddComponent(FixedJoint);
joint.connectedBody = c.rigidbody;
}
}
Any help is much appreciated. If it's the Unity reference link about collision your going to reference, slaps hand no, no lol. I already read that but there are no examples for the asset specific tag names affecting eachother to apply the function of "Stick" in the basic reference page that I found there.
Looks like your almost there to me, if I understand, which I might not!
You are checking that c.gameObject.tag == "Stick" and you only want that to work if the object sticking has a tag of "A" right?
Either only attach this code to the object you have tagged A or put an if(gameObject.tag == "A") around the if(c.gameObject.tag == "Stick")
Remember tag is just a "string" that is a property of your gameObject - the only thing special about it is there are ways of finding objects using it.
Your answer
![](https://koobas.hobune.stream/wayback/20220613071800im_/https://answers.unity.com/themes/thub/images/avi.jpg)