- Home /
Question by
harethl1s · Mar 17, 2020 at 03:36 PM ·
collidertransformcollision detection
How to check if there is object before placing one?
Hi,I have created a 3d game based on 2d view anyways, I made script when you click it places a gameobject, i want to check before placing the object if there is any object exist in the mouse positon here is the placing code
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Vector3 touchPos = mainCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 4.64f ));
// a small check to see if the object placed less than 2 in height (to avoid ground conculusion)
if (touchPos.y < 2.5f)
{
}
else
{
// placing code
Instantiate(plat1, touchPos, Quaternion.identity);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
C# Probability of Transform Colliding 1 Answer
Best collision detection method? 2 Answers
convert a collider array to a list transform 1 Answer
Why when i move the player object through the door the ontriggerenter/exit event are not fire ? 2 Answers
Stick a projectile to an object (arrow into an object) 2 Answers