- Home /
Question is off-topic or not relevant
player hits a key and creates a primitive
I would like to know how I can get it so, if my player clicks the "g" key that a primitive (cube, sphere etc.) appears in game on the ground in front of him. Even more so, a premade model instead of a primitive. Thanks
Have you done any research on this? Google, for example? I know this has been asked and answered many times.
Answer by Jona-Marklund · Aug 27, 2013 at 09:53 PM
Yeah, simply like this.
public GameObject go;
void Update()
{
if (Input.GetKeyDown("g"))
{
Instantiate(go, Vector3.zero, Quaternion.identity);
}
}
public Transform playerPosition;
Instantiate(tempest, playerPosition.position + new Vector3(X,X,X), Quaternion.identity);
so when i do that code above it drops the object at 0,0,0. How do i get it to drop right in front of the player view?
See GameObject.CreatePrimitive(). Use the following to put calculate a position at the center of the game view 10 units from the camera:
Vector3 v = new Vector3(0.5f, 0.5f, 10.0f);
v = Camera.main.ViewportToWorldPoint(v);
Follow this Question
Related Questions
how to make primitive dynamically in game 0 Answers
How I can create a cube using vectors? 1 Answer
CREATING A TERRAIN 3 Answers
Cloud System: Ideas to Create 0 Answers
Create scenes at runtime 2 Answers