- Home /
Building objects in-game
#pragma strict
var build : GameObject;
function Update ()
{
if (Input.GetKeyDown(KeyCode.B))
{
build = Instantiate(build, transform.position + transform.forward * 4.0 , transform.rotation);
build.rigidbody.isKinematic = true;
build.transform.parent = Camera.main.transform;
if(Input.GetKeyDown(KeyCode.V))
{
build.transform.parent = null;
build.rigidbody.isKinematic = false;
}
}
}
I want to create object in game. When i click B it create cube in front of my screen. I want to move it by X and Z not Y, it must be all the time on the ground. Its like in Rust game. When i want to build it i press V and he put it on the ground. What i must do with this code ? ;/ Can u help me ?
Solving the specific problems you list is not too hard, but there are other problems that are not addressed by this approach. First most people who what this kind of code, also don't want object to go through each other. Second most people don't want to allow one object to be placed within another. Both require different/more code.
And -1 i dont know why. I need some example, maybe links or whatever ...
Converted your answer to a comment. This is not a forum. It is clear that you have a long way to go before making the next DayZ or Rust. Please take topics like this to the forum and ask specific solvable questions on this site. see the FAQ for details on how to use this site.
I dont do this, i just want learn something i need this to my project not next survival game >.>
This code-fixing question might derive in a long discussion on best program$$anonymous$$g practices, consider using Unity Forums to share ideas on these topics. Please help us improve Unity Answers with concrete questions and answers, Unity Forums is a great place post and review code. Thanks for your comprehension, Unity Support.