- Home /
How to store player model and then swap the model to an object I Raycast hit?
Hello! I have a player object with a player model as a child. (Not sure if I am saying that correctly) What I am trying to do is, when I Raycast hit a specific object (tag based), I would like to press a key and have my current player model transform into the object I Raycast hit.
I have my buttons setup and my raycast is working, I am just having trouble switching my current game model to the object I am looking at.
If anyone can help, it will be greatly appreciated. Thank you.
Here is the method I have been working on.
void PlayerTransform() { var ray = Camera.main.ScreenPointToRay(Input.mousePosition); var selection = hit.transform;
if (Input.GetKeyDown(KeyCode.F) && Physics.Raycast(ray, out hit) && selection.CompareTag(interactableTag))
{
//playerMesh = hit.transform.gameObject;
//Destroy(playerMesh);
}
}
Your answer
Follow this Question
Related Questions
Bottom area of a 3D model? Raycast? 1 Answer
Raycast Gun Fire Rate 0 Answers
Help getting Raycast last hit data 2 Answers
Using raycasts to move a game object toward touch point. 0 Answers
How do I make it know what it's hitting? 3 Answers