- Home /
does not want to setparent
When you drive up to the trigger zone when you press a key, the object does not want to beat 0 attention with the parent here is the code void OnTriggeStay(Collider other) {
if (other.CompareTag ("Player") && Input.GetKey(KeyCode.E) ) {
transform.SetParent (Player.transform);
}
}
Answer by sean244 · Jan 04, 2019 at 09:32 PM
What about rewriting it like this
private void OnTriggerStay(Collider other)
{
if (other.CompareTag("Player"))
{
if (Input.GetKey(KeyCode.E))
{
transform.SetParent(other.transform);
}
}
}
I assume it's the transform.SetParent(other.transform); line that did the trick? Because I see no reason why ifs should be separated, it should be the exact same thing
Possibly. I'm not sure why his original code didn't work. I just rewrote his if statement to a nested one because it's more readable, but it's possible that it was only the transform.SetParent(other.transform);
function that mattered.
Answer by Vilhien · Jan 04, 2019 at 07:35 PM
Try switching your statement to say if(other.transform.tag=="Player"&&Input...
Also not sure if it matters but get rid of the space between SetParent(Player.transform);
That's all done but nothing comes
void OnTriggeStay(Collider other)
{
if (other.transform.tag == "Player" && Input.Get$$anonymous$$ey($$anonymous$$eyCode.E) ) {
transform.SetParent(Player.transform);
}
}
Your answer
Follow this Question
Related Questions
How do I access the contents of a script from another script? 2 Answers
How can I write this code, from C# to JavaScript? 2 Answers
How can i using a break point if a gameobject have a collider after added to it ? 1 Answer
How can i make enum choice to not pause the game ? 0 Answers
Can't move Camera Position using Script 2 Answers