In need of some help with clones!
I am currently in the works of a 3D block builder game, and I am having trouble spawning a clone but only when there is no clone there already. I am new to Unity, so there are a few things I still need to learn. Do I need to use the OnColliderEnter() void or the OnTriggerEnter() void? Or do I need to make it with just OnCollider()? Please help me as I cannot really progress on my game without.
Here is the code for the block placing:
if (Input.GetMouseButtonDown(0))
{
ShouldPlace = 1;
}
else
{
ShouldPlace = 0;
}
if (ShouldPlace == 1)
{
BlockPlaced = Instantiate(CurrentBlock, new Vector3(BlockCursor.transform.position.x, BlockCursor.transform.position.y, BlockCursor.transform.position.z), BlockCursor.transform.rotation);
}
And here's the code for the block destruction:
public GameObject BlockCursor;
private void Start()
{
BlockCursor = GameObject.FindGameObjectWithTag("Cursor");
}
void Update()
{
if (Input.GetMouseButtonDown(1) && transform.position == BlockCursor.transform.position)
{
Destroy(this.gameObject);
}
}
Thank you in advance.
Answer by streeetwalker · Feb 27, 2020 at 07:18 AM
Can you describe the mechanics of your game further? How do you imagine it behaving: you click to anywhere place the first and it falls to the ground, and likewise with the other blocks, or what - you want to click on one block to place another on top of it?
So where exactly is the problem of placing the first block, because it doesn't look like there is one in your code, unless that code is attached to your block prefabs. It doesn't need to to be....
Which collision detection you use depends on what you want to have happen when there is a collision. If you use trigger event detection you must set one object's collider component option to "is Trigger" and there will be no physical collision - the objects can pass through each other - it doesn't sound like that is what you want.