Answer the question
In order to leave comments, you need to log in
How to make a character enter the trigger, the player presses a button on the keyboard and this character becomes a child object of another object?
It is necessary that the Persian, when he enters the cube, which is a trigger, the player presses a button on the keyboard and the Persian takes control of the ship.
Answer the question
In order to leave comments, you need to log in
https://docs.unity3d.com/ScriptReference/Collider.... - when the object is in the trigger
https://docs.unity3d.com/ScriptReference/Transform... - we assign the parent
The code will look something like this if I understood you correctly:
//imaginary variables
public Transform previousParent;
public GameObject ship;
public GameObject player;
bool isNearWheel;
private void Update()
{
if (Input.GetKey(KeyCode.F) && isNearWheel)
player.transform.SetParent(ship.transform);
}
private void OnTriggerStay(Collider other)
{
if (other.tag == "wheel")
isNearWheel = true;
else isNearWheel = false;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question